TechDraw: Insert tool insert DrawViewProjGroupItem that can then be transfered into groups and back.
This commit is contained in:
@@ -542,9 +542,8 @@ int DrawProjGroup::purgeProjections()
|
||||
{
|
||||
while (!Views.getValues().empty()) {
|
||||
std::vector<DocumentObject*> views = Views.getValues();
|
||||
DrawProjGroupItem* dpgi;
|
||||
DocumentObject* dObj = views.back();
|
||||
dpgi = dynamic_cast<DrawProjGroupItem*>(dObj);
|
||||
auto* dpgi = dynamic_cast<DrawProjGroupItem*>(dObj);
|
||||
if (dpgi) {
|
||||
std::string itemName = dpgi->Type.getValueAsString();
|
||||
removeProjection(itemName.c_str());
|
||||
@@ -1077,8 +1076,7 @@ TechDraw::DrawProjGroupItem* DrawProjGroup::getAnchor()
|
||||
{
|
||||
App::DocumentObject* docObj = Anchor.getValue();
|
||||
if (docObj) {
|
||||
DrawProjGroupItem* result = static_cast<DrawProjGroupItem*>(docObj);
|
||||
return result;
|
||||
return static_cast<DrawProjGroupItem*>(docObj);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@@ -1086,7 +1084,7 @@ TechDraw::DrawProjGroupItem* DrawProjGroup::getAnchor()
|
||||
void DrawProjGroup::setAnchorDirection(const Base::Vector3d dir)
|
||||
{
|
||||
App::DocumentObject* docObj = Anchor.getValue();
|
||||
DrawProjGroupItem* item = static_cast<DrawProjGroupItem*>(docObj);
|
||||
auto* item = static_cast<DrawProjGroupItem*>(docObj);
|
||||
item->Direction.setValue(dir);
|
||||
}
|
||||
|
||||
@@ -1096,7 +1094,7 @@ Base::Vector3d DrawProjGroup::getAnchorDirection()
|
||||
if (!docObj) {
|
||||
return Base::Vector3d();
|
||||
}
|
||||
DrawProjGroupItem* item = static_cast<DrawProjGroupItem*>(docObj);
|
||||
auto* item = static_cast<DrawProjGroupItem*>(docObj);
|
||||
return item->Direction.getValue();
|
||||
}
|
||||
|
||||
@@ -1239,8 +1237,7 @@ std::vector<DrawProjGroupItem*> DrawProjGroup::getViewsAsDPGI()
|
||||
std::vector<DrawProjGroupItem*> result;
|
||||
auto views = Views.getValues();
|
||||
for (auto& v : views) {
|
||||
DrawProjGroupItem* item = static_cast<DrawProjGroupItem*>(v);
|
||||
result.push_back(item);
|
||||
result.push_back(static_cast<DrawProjGroupItem*>(v));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1256,7 +1253,7 @@ void DrawProjGroup::dumpISO(const char* title)
|
||||
for (auto& docObj : Views.getValues()) {
|
||||
Base::Vector3d dir;
|
||||
Base::Vector3d axis;
|
||||
DrawProjGroupItem* v = static_cast<DrawProjGroupItem*>(docObj);
|
||||
auto* v = static_cast<DrawProjGroupItem*>(docObj);
|
||||
std::string t = v->Type.getValueAsString();
|
||||
dir = v->Direction.getValue();
|
||||
axis = v->getXDirection();
|
||||
|
||||
@@ -55,7 +55,7 @@ const char *DrawProjGroupItem::TypeEnums[] = {
|
||||
|
||||
PROPERTY_SOURCE(TechDraw::DrawProjGroupItem, TechDraw::DrawViewPart)
|
||||
|
||||
DrawProjGroupItem::DrawProjGroupItem(void)
|
||||
DrawProjGroupItem::DrawProjGroupItem()
|
||||
{
|
||||
Type.setEnums(TypeEnums);
|
||||
ADD_PROPERTY(Type, ((long)0));
|
||||
@@ -65,30 +65,25 @@ DrawProjGroupItem::DrawProjGroupItem(void)
|
||||
//projection group controls these
|
||||
// Direction.setStatus(App::Property::ReadOnly, true);
|
||||
RotationVector.setStatus(App::Property::ReadOnly, true); //Use XDirection
|
||||
ScaleType.setValue("Custom");
|
||||
Scale.setStatus(App::Property::Hidden, true);
|
||||
ScaleType.setStatus(App::Property::Hidden, true);
|
||||
}
|
||||
|
||||
short DrawProjGroupItem::mustExecute() const
|
||||
{
|
||||
//there is nothing unique about dpgi vs dvp
|
||||
return TechDraw::DrawViewPart::mustExecute();
|
||||
if (getPGroup()) {
|
||||
ScaleType.setValue("Custom");
|
||||
Scale.setStatus(App::Property::Hidden, true);
|
||||
ScaleType.setStatus(App::Property::Hidden, true);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawProjGroupItem::onChanged(const App::Property *prop)
|
||||
{
|
||||
if ((prop == &X) ||
|
||||
(prop == &Y)) {
|
||||
DrawProjGroup* parent = getPGroup();
|
||||
if (parent) {
|
||||
parent->touch(false);
|
||||
if ((prop == &X) || (prop == &Y)) {
|
||||
DrawProjGroup* pGroup = getPGroup();
|
||||
if (pGroup) {
|
||||
pGroup->touch(false);
|
||||
}
|
||||
}
|
||||
TechDraw::DrawViewPart::onChanged(prop);
|
||||
}
|
||||
|
||||
bool DrawProjGroupItem::isLocked(void) const
|
||||
bool DrawProjGroupItem::isLocked() const
|
||||
{
|
||||
if (isAnchor()) { //Anchor view is always locked to DPG
|
||||
return true;
|
||||
@@ -96,23 +91,22 @@ bool DrawProjGroupItem::isLocked(void) const
|
||||
return DrawView::isLocked();
|
||||
}
|
||||
|
||||
bool DrawProjGroupItem::showLock(void) const
|
||||
bool DrawProjGroupItem::showLock() const
|
||||
{
|
||||
DrawProjGroup* parent = getPGroup();
|
||||
bool parentLock = false;
|
||||
if (parent) {
|
||||
parentLock = parent->LockPosition.getValue();
|
||||
}
|
||||
|
||||
if (isAnchor() && //don't show lock for Front if DPG is not locked
|
||||
!parentLock) {
|
||||
//don't show lock for Front if DPG is not locked
|
||||
if (isAnchor() && !parentLock) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return DrawView::showLock();
|
||||
}
|
||||
|
||||
App::DocumentObjectExecReturn *DrawProjGroupItem::execute(void)
|
||||
App::DocumentObjectExecReturn *DrawProjGroupItem::execute()
|
||||
{
|
||||
// Base::Console().Message("DPGI::execute() - %s / %s\n", getNameInDocument(), Label.getValue());
|
||||
if (!keepUpdated()) {
|
||||
@@ -132,40 +126,46 @@ App::DocumentObjectExecReturn *DrawProjGroupItem::execute(void)
|
||||
//unblock
|
||||
}
|
||||
|
||||
if (DrawUtil::checkParallel(Direction.getValue(),
|
||||
getXDirection())) {
|
||||
if (DrawUtil::checkParallel(Direction.getValue(), getXDirection())) {
|
||||
return new App::DocumentObjectExecReturn("DPGI: Direction and XDirection are parallel");
|
||||
}
|
||||
|
||||
return DrawViewPart::execute();
|
||||
}
|
||||
|
||||
void DrawProjGroupItem::postHlrTasks(void)
|
||||
void DrawProjGroupItem::postHlrTasks()
|
||||
{
|
||||
// Base::Console().Message("DPGI::postHlrTasks() - %s\n", getNameInDocument());
|
||||
DrawViewPart::postHlrTasks();
|
||||
|
||||
//DPGI has no geometry until HLR has finished, and the DPG can not properly
|
||||
//AutoDistibute until all its items have geometry.
|
||||
autoPosition();
|
||||
DrawProjGroup* pGroup = getPGroup();
|
||||
if (pGroup) {
|
||||
//DPGI has no geometry until HLR has finished, and the DPG can not properly
|
||||
//AutoDistibute until all its items have geometry.
|
||||
autoPosition();
|
||||
|
||||
getPGroup()->reportReady(); //tell the parent DPG we are ready
|
||||
pGroup->reportReady(); //tell the parent DPG we are ready
|
||||
}
|
||||
}
|
||||
|
||||
void DrawProjGroupItem::autoPosition()
|
||||
{
|
||||
DrawProjGroup* pGroup = getPGroup();
|
||||
if (!pGroup) {
|
||||
return;
|
||||
}
|
||||
// Base::Console().Message("DPGI::autoPosition(%s)\n", Label.getValue());
|
||||
if (LockPosition.getValue()) {
|
||||
return;
|
||||
}
|
||||
Base::Vector3d newPos;
|
||||
if (getPGroup() && getPGroup()->AutoDistribute.getValue()) {
|
||||
newPos = getPGroup()->getXYPosition(Type.getValueAsString());
|
||||
if (pGroup && pGroup->AutoDistribute.getValue()) {
|
||||
newPos = pGroup->getXYPosition(Type.getValueAsString());
|
||||
X.setValue(newPos.x);
|
||||
Y.setValue(newPos.y);
|
||||
requestPaint();
|
||||
purgeTouched(); //prevents "still touched after recompute" message
|
||||
getPGroup()->purgeTouched(); //changing dpgi x, y marks parent dpg as touched
|
||||
pGroup->purgeTouched(); //changing dpgi x, y marks parent dpg as touched
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,49 +184,12 @@ DrawProjGroup* DrawProjGroupItem::getPGroup() const
|
||||
return dynamic_cast<DrawProjGroup *>(getCollection());
|
||||
}
|
||||
|
||||
bool DrawProjGroupItem::isAnchor(void) const
|
||||
bool DrawProjGroupItem::isAnchor() const
|
||||
{
|
||||
if (getPGroup() && (getPGroup()->getAnchor() == this) ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return getPGroup() && (getPGroup()->getAnchor() == this);
|
||||
}
|
||||
|
||||
/// get a coord system aligned with Direction and Rotation Vector
|
||||
gp_Ax2 DrawProjGroupItem::getViewAxis(const Base::Vector3d& pt,
|
||||
const Base::Vector3d& axis,
|
||||
const bool flip) const
|
||||
{
|
||||
Base::Console().Message("DPGI::getViewAxis - deprecated. use getProjectionCS\n");
|
||||
(void) flip;
|
||||
gp_Ax2 viewAxis;
|
||||
Base::Vector3d projDir = Direction.getValue();
|
||||
Base::Vector3d rotVec = getXDirection();
|
||||
|
||||
// mirror projDir through XZ plane
|
||||
Base::Vector3d yNorm(0.0, 1.0, 0.0);
|
||||
projDir = projDir - (yNorm * 2.0) * (projDir.Dot(yNorm));
|
||||
rotVec = rotVec - (yNorm * 2.0) * (rotVec.Dot(yNorm));
|
||||
|
||||
if (DrawUtil::checkParallel(projDir, rotVec)) {
|
||||
Base::Console().Warning("DPGI::getVA - %s - Direction and XDirection parallel. using defaults\n",
|
||||
getNameInDocument());
|
||||
}
|
||||
try {
|
||||
viewAxis = gp_Ax2(gp_Pnt(pt.x, pt.y, pt.z),
|
||||
gp_Dir(projDir.x, projDir.y, projDir.z),
|
||||
gp_Dir(rotVec.x, rotVec.y, rotVec.z));
|
||||
}
|
||||
catch (Standard_Failure& e4) {
|
||||
Base::Console().Message("PROBLEM - DPGI (%s) failed to create viewAxis: %s **\n",
|
||||
getNameInDocument(), e4.GetMessageString());
|
||||
return ShapeUtils::getViewAxis(pt, axis, false);
|
||||
}
|
||||
|
||||
return viewAxis;
|
||||
}
|
||||
|
||||
Base::Vector3d DrawProjGroupItem::getXDirection(void) const
|
||||
Base::Vector3d DrawProjGroupItem::getXDirection() const
|
||||
{
|
||||
// Base::Console().Message("DPGI::getXDirection() - %s\n", Label.getValue());
|
||||
Base::Vector3d result(1.0, 0.0, 0.0); //default X
|
||||
@@ -237,19 +200,23 @@ Base::Vector3d DrawProjGroupItem::getXDirection(void) const
|
||||
prop = getPropertyByName("RotationVector");
|
||||
if (prop) {
|
||||
result = RotationVector.getValue(); //use RotationVector if we have it
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
result = DrawViewPart::getXDirection(); //over complex.
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
result = DrawViewPart::getXDirection();
|
||||
}
|
||||
} else { //not sure this branch can actually happen
|
||||
}
|
||||
else { //not sure this branch can actually happen
|
||||
Base::Console().Message("DPGI::getXDirection - unexpected branch taken!\n");
|
||||
prop = getPropertyByName("RotationVector");
|
||||
if (prop) {
|
||||
result = RotationVector.getValue();
|
||||
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
Base::Console().Message("DPGI::getXDirection - missing RotationVector and XDirection\n");
|
||||
}
|
||||
}
|
||||
@@ -309,7 +276,7 @@ double DrawProjGroupItem::getRotateAngle()
|
||||
return angle;
|
||||
}
|
||||
|
||||
double DrawProjGroupItem::getScale(void) const
|
||||
double DrawProjGroupItem::getScale() const
|
||||
{
|
||||
auto pgroup = getPGroup();
|
||||
if (pgroup) {
|
||||
@@ -319,7 +286,7 @@ double DrawProjGroupItem::getScale(void) const
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return 1.0;
|
||||
return Scale.getValue();
|
||||
}
|
||||
|
||||
int DrawProjGroupItem::getScaleType() const
|
||||
@@ -339,13 +306,12 @@ void DrawProjGroupItem::unsetupObject()
|
||||
return;
|
||||
}
|
||||
|
||||
if (!getPGroup()->hasProjection(Type.getValueAsString()) ) {
|
||||
if (!getPGroup()->hasProjection(Type.getValueAsString())) {
|
||||
DrawViewPart::unsetupObject();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( getPGroup()->getAnchor() == this &&
|
||||
!getPGroup()->isUnsetting() ) {
|
||||
if (getPGroup()->getAnchor() == this && !getPGroup()->isUnsetting()) {
|
||||
Base::Console().Warning("Warning - DPG (%s/%s) may be corrupt - Anchor deleted\n",
|
||||
getPGroup()->getNameInDocument(), getPGroup()->Label.getValue());
|
||||
getPGroup()->Anchor.setValue(nullptr); //this catches situation where DPGI is deleted w/o DPG::removeProjection
|
||||
@@ -361,7 +327,7 @@ int DrawProjGroupItem::countParentPages() const
|
||||
if (dpg) {
|
||||
return dpg->countParentPages();
|
||||
}
|
||||
return 0;
|
||||
return DrawView::countParentPages();
|
||||
}
|
||||
|
||||
DrawPage* DrawProjGroupItem::findParentPage() const
|
||||
@@ -370,7 +336,7 @@ DrawPage* DrawProjGroupItem::findParentPage() const
|
||||
if (dpg) {
|
||||
return dpg->findParentPage();
|
||||
}
|
||||
return nullptr;
|
||||
return DrawView::findParentPage();
|
||||
}
|
||||
|
||||
std::vector<DrawPage*> DrawProjGroupItem::findAllParentPages() const
|
||||
@@ -379,10 +345,10 @@ std::vector<DrawPage*> DrawProjGroupItem::findAllParentPages() const
|
||||
if (dpg) {
|
||||
return dpg->findAllParentPages();
|
||||
}
|
||||
return std::vector<DrawPage*>();
|
||||
return DrawView::findAllParentPages();
|
||||
}
|
||||
|
||||
PyObject *DrawProjGroupItem::getPyObject(void)
|
||||
PyObject *DrawProjGroupItem::getPyObject()
|
||||
{
|
||||
if (PythonObject.is(Py::_None())) {
|
||||
// ref counter is set to 1
|
||||
|
||||
@@ -60,7 +60,6 @@ public:
|
||||
App::PropertyEnumeration Type;
|
||||
App::PropertyVector RotationVector; //this is superseded by dvp xdirection
|
||||
|
||||
short mustExecute() const override;
|
||||
void onDocumentRestored() override;
|
||||
void unsetupObject() override;
|
||||
|
||||
@@ -81,10 +80,6 @@ public:
|
||||
//return PyObject as DrawProjGroupItemPy
|
||||
PyObject *getPyObject() override;
|
||||
|
||||
gp_Ax2 getViewAxis(const Base::Vector3d& pt,
|
||||
const Base::Vector3d& direction,
|
||||
const bool flip=true) const override;
|
||||
|
||||
double getScale() const override;
|
||||
int getScaleType() const override;
|
||||
void autoPosition();
|
||||
|
||||
Reference in New Issue
Block a user