From 9d9d41bcd0066ce2a398cbd79c88ee1f586f4d52 Mon Sep 17 00:00:00 2001 From: wandererfan Date: Sun, 17 Nov 2019 13:55:19 -0500 Subject: [PATCH] [TD]correct alignment of Section & Detail with Base --- src/Mod/TechDraw/App/DrawProjGroup.cpp | 30 +- src/Mod/TechDraw/App/DrawProjGroupItem.cpp | 81 +++++- src/Mod/TechDraw/App/DrawProjGroupItem.h | 6 +- src/Mod/TechDraw/App/DrawProjectSplit.cpp | 3 +- src/Mod/TechDraw/App/DrawUtil.cpp | 4 +- src/Mod/TechDraw/App/DrawViewDetail.cpp | 97 +++--- src/Mod/TechDraw/App/DrawViewDetail.h | 1 + src/Mod/TechDraw/App/DrawViewPart.cpp | 201 +++++++++---- src/Mod/TechDraw/App/DrawViewPart.h | 34 ++- src/Mod/TechDraw/App/DrawViewSection.cpp | 324 +++++++-------------- src/Mod/TechDraw/App/DrawViewSection.h | 7 +- src/Mod/TechDraw/App/GeometryObject.cpp | 210 ++++++++++--- src/Mod/TechDraw/App/GeometryObject.h | 8 + src/Mod/TechDraw/Gui/Command.cpp | 12 + src/Mod/TechDraw/Gui/DrawGuiUtil.cpp | 8 +- src/Mod/TechDraw/Gui/QGIView.cpp | 1 + src/Mod/TechDraw/Gui/QGIViewPart.cpp | 16 +- 17 files changed, 625 insertions(+), 418 deletions(-) diff --git a/src/Mod/TechDraw/App/DrawProjGroup.cpp b/src/Mod/TechDraw/App/DrawProjGroup.cpp index e10a52b6c3..9eaa39edf2 100644 --- a/src/Mod/TechDraw/App/DrawProjGroup.cpp +++ b/src/Mod/TechDraw/App/DrawProjGroup.cpp @@ -421,7 +421,7 @@ App::DocumentObject * DrawProjGroup::addProjection(const char *viewProjType) if (strcmp(viewProjType, "Front") != 0 ) { //not Front! vecs = getDirsFromFront(view); view->Direction.setValue(vecs.first); - view->RotationVector.setValue(vecs.second); + view->XDirection.setValue(vecs.second); view->recomputeFeature(); } else { //Front Anchor.setValue(view); @@ -516,7 +516,7 @@ std::pair DrawProjGroup::getDirsFromFront(std::st } Base::Vector3d dirAnch = anch->Direction.getValue(); - Base::Vector3d rotAnch = anch->RotationVector.getValue(); + Base::Vector3d rotAnch = anch->getXDirection(); Base::Vector3d upAnch = dirAnch.Cross(rotAnch); //this can get weird after rotations projDir = dirAnch; //need default rotVec = rotAnch; @@ -1034,7 +1034,7 @@ void DrawProjGroup::updateSecondaryDirs() { DrawProjGroupItem* anchor = getAnchor(); Base::Vector3d anchDir = anchor->Direction.getValue(); - Base::Vector3d anchRot = anchor->RotationVector.getValue(); + Base::Vector3d anchRot = anchor->getXDirection(); std::map > saveVals; std::string key; @@ -1120,11 +1120,11 @@ void DrawProjGroup::updateSecondaryDirs() //TARFU invalid secondary type Base::Console().Message("ERROR - DPG::updateSecondaryDirs - invalid projection type\n"); newDir = v->Direction.getValue(); - newRot = v->RotationVector.getValue(); + newRot = v->getXDirection(); } } // v->Direction.setValue(newDir); -// v->RotationVector.setValue(newRot); +// v->XDirection.setValue(newRot); } //not sure if this is required. @@ -1133,7 +1133,7 @@ void DrawProjGroup::updateSecondaryDirs() std::string type = v->Type.getValueAsString(); data = saveVals[type]; v->Direction.setValue(data.first); - v->RotationVector.setValue(data.second); + v->XDirection.setValue(data.second); } auto page = findParentPage(); @@ -1149,7 +1149,7 @@ void DrawProjGroup::rotateRight() newDirs = getDirsFromFront("Left"); DrawProjGroupItem* anchor = getAnchor(); anchor->Direction.setValue(newDirs.first); - anchor->RotationVector.setValue(newDirs.second); + anchor->XDirection.setValue(newDirs.second); updateSecondaryDirs(); } @@ -1160,7 +1160,7 @@ void DrawProjGroup::rotateLeft() newDirs = getDirsFromFront("Right"); DrawProjGroupItem* anchor = getAnchor(); anchor->Direction.setValue(newDirs.first); - anchor->RotationVector.setValue(newDirs.second); + anchor->XDirection.setValue(newDirs.second); updateSecondaryDirs(); } @@ -1171,7 +1171,7 @@ void DrawProjGroup::rotateUp() newDirs = getDirsFromFront("Bottom"); DrawProjGroupItem* anchor = getAnchor(); anchor->Direction.setValue(newDirs.first); - anchor->RotationVector.setValue(newDirs.second); + anchor->XDirection.setValue(newDirs.second); updateSecondaryDirs(); } @@ -1182,7 +1182,7 @@ void DrawProjGroup::rotateDown() newDirs = getDirsFromFront("Top"); DrawProjGroupItem* anchor = getAnchor(); anchor->Direction.setValue(newDirs.first); - anchor->RotationVector.setValue(newDirs.second); + anchor->XDirection.setValue(newDirs.second); updateSecondaryDirs(); } @@ -1192,10 +1192,10 @@ void DrawProjGroup::spinCW() DrawProjGroupItem* anchor = getAnchor(); double angle = M_PI / 2.0; Base::Vector3d org(0.0,0.0,0.0); - Base::Vector3d curRot = anchor->RotationVector.getValue(); + Base::Vector3d curRot = anchor->getXDirection(); Base::Vector3d curDir = anchor->Direction.getValue(); Base::Vector3d newRot = DrawUtil::vecRotate(curRot,angle,curDir,org); - anchor->RotationVector.setValue(newRot); + anchor->XDirection.setValue(newRot); updateSecondaryDirs(); } @@ -1205,10 +1205,10 @@ void DrawProjGroup::spinCCW() DrawProjGroupItem* anchor = getAnchor(); double angle = M_PI / 2.0; Base::Vector3d org(0.0,0.0,0.0); - Base::Vector3d curRot = anchor->RotationVector.getValue(); + Base::Vector3d curRot = anchor->getXDirection(); Base::Vector3d curDir = anchor->Direction.getValue(); Base::Vector3d newRot = DrawUtil::vecRotate(curRot,-angle,curDir,org); - anchor->RotationVector.setValue(newRot); + anchor->XDirection.setValue(newRot); updateSecondaryDirs(); } @@ -1244,7 +1244,7 @@ void DrawProjGroup::dumpISO(const char * title) DrawProjGroupItem* v = static_cast(docObj); std::string t = v->Type.getValueAsString(); dir = v->Direction.getValue(); - axis = v->RotationVector.getValue(); + axis = v->getXDirection(); Base::Console().Message("%s: %s/%s\n", t.c_str(),DrawUtil::formatVector(dir).c_str(),DrawUtil::formatVector(axis).c_str()); diff --git a/src/Mod/TechDraw/App/DrawProjGroupItem.cpp b/src/Mod/TechDraw/App/DrawProjGroupItem.cpp index 09f0e29907..20e33f3534 100644 --- a/src/Mod/TechDraw/App/DrawProjGroupItem.cpp +++ b/src/Mod/TechDraw/App/DrawProjGroupItem.cpp @@ -64,11 +64,12 @@ DrawProjGroupItem::DrawProjGroupItem(void) { Type.setEnums(TypeEnums); ADD_PROPERTY(Type, ((long)0)); - ADD_PROPERTY_TYPE(RotationVector ,(1.0,0.0,0.0) ,"Base",App::Prop_None,"Controls rotation of item in view. "); + ADD_PROPERTY_TYPE(RotationVector ,(1.0,0.0,0.0) ,"Base", + App::Prop_None,"Deprecated. Use XDirection."); //projection group controls these // Direction.setStatus(App::Property::ReadOnly,true); -// RotationVector.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); @@ -83,7 +84,7 @@ short DrawProjGroupItem::mustExecute() const short result = 0; if (!isRestoring()) { result = (Direction.isTouched() || - RotationVector.isTouched() || + XDirection.isTouched() || Source.isTouched() || Scale.isTouched()); } @@ -135,8 +136,8 @@ App::DocumentObjectExecReturn *DrawProjGroupItem::execute(void) { // Base::Console().Message("DPGI::execute(%s)\n",Label.getValue()); if (DrawUtil::checkParallel(Direction.getValue(), - RotationVector.getValue())) { - return new App::DocumentObjectExecReturn("DPGI: Direction and RotationVector are parallel"); + getXDirection())) { + return new App::DocumentObjectExecReturn("DPGI: Direction and XDirection are parallel"); } App::DocumentObjectExecReturn* ret = DrawViewPart::execute(); @@ -201,10 +202,11 @@ 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 = RotationVector.getValue(); + Base::Vector3d rotVec = getXDirection(); // mirror projDir through XZ plane Base::Vector3d yNorm(0.0,1.0,0.0); @@ -212,7 +214,7 @@ gp_Ax2 DrawProjGroupItem::getViewAxis(const Base::Vector3d& pt, rotVec = rotVec - (yNorm * 2.0) * (rotVec.Dot(yNorm)); if (DrawUtil::checkParallel(projDir,rotVec)) { - Base::Console().Warning("DPGI::getVA - %s - Direction and RotationVector parallel. using defaults\n", + Base::Console().Warning("DPGI::getVA - %s - Direction and XDirection parallel. using defaults\n", getNameInDocument()); } try { @@ -229,19 +231,78 @@ gp_Ax2 DrawProjGroupItem::getViewAxis(const Base::Vector3d& pt, return viewAxis; } +Base::Vector3d DrawProjGroupItem::getXDirection(void) const +{ +// Base::Console().Message("DPGI::getXDirection() - %s\n", Label.getValue()); + Base::Vector3d result(1.0, 0.0, 0.0); //default X + App::Property* prop = getPropertyByName("XDirection"); + if (prop != nullptr) { + Base::Vector3d propVal = XDirection.getValue(); + if (DrawUtil::fpCompare(propVal.Length(), 0.0)) { //have XDirection property, but not set + prop = getPropertyByName("RotationVector"); + if (prop != nullptr) { + result = RotationVector.getValue(); //use RotationVector if we have it + } else { + result = DrawViewPart::getXDirection(); //over complex. + } + } else { + result = DrawViewPart::getXDirection(); + } + } else { //not sure this branch can actually happen + Base::Console().Message("DPGI::getXDirection - unexpected branch taken!\n"); + prop = getPropertyByName("RotationVector"); + if (prop != nullptr) { + result = RotationVector.getValue(); + + } else { + Base::Console().Message("DPGI::getXDirection - missing RotationVector and XDirection\n"); + } + } + return result; +} + +Base::Vector3d DrawProjGroupItem::getLegacyX(const Base::Vector3d& pt, + const Base::Vector3d& axis, + const bool flip) const +{ +// Base::Console().Message("DPGI::getLegacyX() - %s\n", Label.getValue()); + Base::Vector3d result(1.0, 0.0, 0.0); + App::Property* prop = getPropertyByName("RotationVector"); + if (prop != nullptr) { + result = RotationVector.getValue(); + if (DrawUtil::fpCompare(result.Length(), 0.0)) { //have RotationVector property, but not set + gp_Ax2 va = getViewAxis(pt, + axis, + flip); + gp_Dir gXDir = va.XDirection(); + result = Base::Vector3d(gXDir.X(), + gXDir.Y(), + gXDir.Z()); + } + } else { + gp_Ax2 va = getViewAxis(pt, + axis, + flip); + gp_Dir gXDir = va.XDirection(); + result = Base::Vector3d(gXDir.X(), + gXDir.Y(), + gXDir.Z()); + } + return result; +} + //get the angle between the current RotationVector vector and the original X dir angle double DrawProjGroupItem::getRotateAngle() { gp_Ax2 viewAxis; - Base::Vector3d x = RotationVector.getValue(); //current rotation + Base::Vector3d x = getXDirection(); //current rotation Base::Vector3d nx = x; nx.Normalize(); Base::Vector3d na = Direction.getValue(); na.Normalize(); Base::Vector3d org(0.0,0.0,0.0); - viewAxis = TechDraw::getViewAxis(org,na,true); //default orientation - + viewAxis = getProjectionCS(org); gp_Dir gxDir = viewAxis.XDirection(); Base::Vector3d origX(gxDir.X(),gxDir.Y(),gxDir.Z()); origX.Normalize(); diff --git a/src/Mod/TechDraw/App/DrawProjGroupItem.h b/src/Mod/TechDraw/App/DrawProjGroupItem.h index f60152143d..d8a7cc0447 100644 --- a/src/Mod/TechDraw/App/DrawProjGroupItem.h +++ b/src/Mod/TechDraw/App/DrawProjGroupItem.h @@ -56,7 +56,7 @@ public: virtual ~DrawProjGroupItem(); App::PropertyEnumeration Type; - App::PropertyVector RotationVector; + App::PropertyVector RotationVector; //this is superceded by dvp xdirection short mustExecute() const override; virtual void onDocumentRestored() override; @@ -64,6 +64,10 @@ public: DrawProjGroup* getPGroup(void) const; double getRotateAngle(); + virtual Base::Vector3d getXDirection(void) const override; + virtual Base::Vector3d getLegacyX(const Base::Vector3d& pt, + const Base::Vector3d& axis, + const bool flip = true) const override; virtual App::DocumentObjectExecReturn *execute(void) override; virtual const char* getViewProviderName(void) const override { diff --git a/src/Mod/TechDraw/App/DrawProjectSplit.cpp b/src/Mod/TechDraw/App/DrawProjectSplit.cpp index b007a86e19..9626ef14ff 100644 --- a/src/Mod/TechDraw/App/DrawProjectSplit.cpp +++ b/src/Mod/TechDraw/App/DrawProjectSplit.cpp @@ -115,7 +115,8 @@ std::vector DrawProjectSplit::getEdgesForWalker(TopoDS_Shape shape, TopoDS_Shape scaledShape; scaledShape = TechDraw::scaleShape(copyShape, scale); - gp_Ax2 viewAxis = TechDraw::getViewAxis(Base::Vector3d(0.0,0.0,0.0),direction); +// gp_Ax2 viewAxis = TechDraw::getViewAxis(Base::Vector3d(0.0,0.0,0.0),direction); + gp_Ax2 viewAxis = TechDraw::legacyViewAxis1(Base::Vector3d(0.0,0.0,0.0),direction); TechDraw::GeometryObject* go = buildGeometryObject(scaledShape,viewAxis); result = getEdges(go); diff --git a/src/Mod/TechDraw/App/DrawUtil.cpp b/src/Mod/TechDraw/App/DrawUtil.cpp index 58e6f6451e..9b0335f5e3 100644 --- a/src/Mod/TechDraw/App/DrawUtil.cpp +++ b/src/Mod/TechDraw/App/DrawUtil.cpp @@ -388,7 +388,7 @@ Base::Vector3d DrawUtil::toR3(const gp_Ax2 fromSystem, const Base::Vector3d from return toPoint; } -//! check if two vectors are parallel +//! check if two vectors are parallel. Vectors don't have to be unit vectors bool DrawUtil::checkParallel(const Base::Vector3d v1, Base::Vector3d v2, double tolerance) { bool result = false; @@ -1100,7 +1100,7 @@ void DrawUtil::dumpCS3(const char* text, gp_Dir baseX = CS.XDirection(); gp_Dir baseY = CS.YDirection(); gp_Pnt baseOrg = CS.Location(); - Base::Console().Message("DU::dumpCS - %s Loc: %s Axis: %s X: %s Y: %s\n", text, + Base::Console().Message("DU::dumpCSF - %s Loc: %s Axis: %s X: %s Y: %s\n", text, DrawUtil::formatVector(baseOrg).c_str(), DrawUtil::formatVector(baseAxis).c_str(), DrawUtil::formatVector(baseX).c_str(), diff --git a/src/Mod/TechDraw/App/DrawViewDetail.cpp b/src/Mod/TechDraw/App/DrawViewDetail.cpp index 694eacaa40..a70066db08 100644 --- a/src/Mod/TechDraw/App/DrawViewDetail.cpp +++ b/src/Mod/TechDraw/App/DrawViewDetail.cpp @@ -115,8 +115,8 @@ DrawViewDetail::DrawViewDetail() m_fudge = 1.01; //hide Properties not relevant to DVDetail - Direction.setStatus(App::Property::Hidden,true); //Should be same as BaseView - Rotation.setStatus(App::Property::Hidden,true); //same as BaseView + Direction.setStatus(App::Property::ReadOnly,true); //Should be same as BaseView + Rotation.setStatus(App::Property::ReadOnly,true); //same as BaseView } @@ -160,6 +160,7 @@ void DrawViewDetail::onChanged(const App::Property* prop) App::DocumentObjectExecReturn *DrawViewDetail::execute(void) { +// Base::Console().Message("DVD::execute() - %s\n", Label.getValue()); if (!keepUpdated()) { return App::DocumentObject::StdReturn; } @@ -230,23 +231,25 @@ App::DocumentObjectExecReturn *DrawViewDetail::execute(void) gp_Ax2 viewAxis; gp_Ax2 vaBase; - viewAxis = dvp->getViewAxis(shapeCenter, dirDetail, true); +// viewAxis = dvp->getProjectionCS(shapeCenter); - copyShape = TechDraw::moveShape(copyShape, //centre shape on origin - -shapeCenter); - gpCenter = TechDraw::findCentroid(copyShape, //sb origin! - dirDetail); - shapeCenter = Base::Vector3d(gpCenter.X(),gpCenter.Y(),gpCenter.Z()); - viewAxis = dvp->getViewAxis(shapeCenter, dirDetail, false); //change view axis to (0,0,0) +// gpCenter = TechDraw::findCentroid(copyShape, //sb origin! +// dirDetail); +// shapeCenter = Base::Vector3d(gpCenter.X(),gpCenter.Y(),gpCenter.Z()); + +// if (dvs != nullptr) { +// Base::Vector3d so = dvs->SectionOrigin.getValue(); +// copyShape = TechDraw::moveShape(copyShape, //centre section shape origin +// -so); +// } else { +// copyShape = TechDraw::moveShape(copyShape, //centre shape on origin +// -shapeCenter); +// } + shapeCenter = Base::Vector3d(0.0, 0.0, 0.0); + + viewAxis = dvp->getProjectionCS(shapeCenter); anchor = Base::Vector3d(anchor.x,anchor.y, 0.0); - if (dvs != nullptr) { - viewAxis = dvs->getSectionCS(); //this goes through SO - gp_Pnt org(0.0, 0.0, 0.0); - viewAxis.SetLocation(org); //move to origin - shapeCenter = Base::Vector3d(0.0, 0.0, 0.0); - anchor = Base::Vector3d(anchor.x, anchor.y, 0.0); - } Base::Vector3d anchorOffset3d = DrawUtil::toR3(viewAxis, anchor); //anchor displacement in R3 @@ -291,9 +294,11 @@ App::DocumentObjectExecReturn *DrawViewDetail::execute(void) } TopoDS_Shape detail = mkCommon.Shape(); -// BRepTools::Write(tool, "DVDTool.brep"); //debug -// BRepTools::Write(copyShape, "DVDCopy.brep"); //debug -// BRepTools::Write(detail, "DVDdetail.brep"); //debug + if (debugDetail()) { + BRepTools::Write(tool, "DVDTool.brep"); //debug + BRepTools::Write(copyShape, "DVDCopy.brep"); //debug + BRepTools::Write(detail, "DVDCommon.brep"); //debug + } Bnd_Box testBox; testBox.SetGap(0.0); @@ -319,28 +324,32 @@ App::DocumentObjectExecReturn *DrawViewDetail::execute(void) try { inputCenter = TechDraw::findCentroid(tool, dirDetail); - TopoDS_Shape mirroredShape = TechDraw::mirrorShape(detail, - inputCenter, - scale); - - if (dvs != nullptr) { - viewAxis = dvs->getSectionCS(); - viewAxis.SetLocation(inputCenter); - } else { - viewAxis = dvp->getViewAxis(Base::Vector3d(inputCenter.X(),inputCenter.Y(),inputCenter.Z()),dirDetail); - } + Base::Vector3d centroid(inputCenter.X(), + inputCenter.Y(), + inputCenter.Z()); - double shapeRotate = dvp->Rotation.getValue(); //degrees CW? - - if (!DrawUtil::fpCompare(shapeRotate,0.0)) { - mirroredShape = TechDraw::rotateShape(mirroredShape, - viewAxis, - shapeRotate); - } + Base::Vector3d stdOrg(0.0,0.0,0.0); + gp_Ax2 viewAxis = dvp->getProjectionCS(stdOrg); //sb same CS as base view. - geometryObject = buildGeometryObject(mirroredShape,viewAxis); - geometryObject->pruneVertexGeom(Base::Vector3d(0.0,0.0,0.0), - Radius.getValue() * scale); //remove vertices beyond clipradius + //center shape on origin + TopoDS_Shape centeredShape = TechDraw::moveShape(detail, + centroid * -1.0); + + TopoDS_Shape scaledShape = TechDraw::scaleShape(centeredShape, + getScale()); + if (!DrawUtil::fpCompare(Rotation.getValue(),0.0)) { + scaledShape = TechDraw::rotateShape(scaledShape, + viewAxis, + Rotation.getValue()); + } + + if (debugDetail()) { + BRepTools::Write(tool, "DVDScaled.brep"); //debug + } + + geometryObject = buildGeometryObject(scaledShape,viewAxis); + geometryObject->pruneVertexGeom(Base::Vector3d(0.0,0.0,0.0), + Radius.getValue() * scale); //remove vertices beyond clipradius #if MOD_TECHDRAW_HANDLE_FACES if (handleFaces()) { @@ -376,6 +385,16 @@ double DrawViewDetail::getFudgeRadius() return Radius.getValue() * m_fudge; } +bool DrawViewDetail::debugDetail(void) const +{ + Base::Reference hGrp = App::GetApplication().GetUserParameter() + .GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/TechDraw/debug"); + + bool result = hGrp->GetBool("debugDetail",false); + return result; +} + + void DrawViewDetail::getParameters() { // what parameters are useful? diff --git a/src/Mod/TechDraw/App/DrawViewDetail.h b/src/Mod/TechDraw/App/DrawViewDetail.h index 6c151376e4..ae31bd0d27 100644 --- a/src/Mod/TechDraw/App/DrawViewDetail.h +++ b/src/Mod/TechDraw/App/DrawViewDetail.h @@ -75,6 +75,7 @@ protected: Base::Vector3d toR3(const gp_Ax2 fromSystem, const Base::Vector3d fromPoint); void getParameters(void); double m_fudge; + bool debugDetail(void) const; }; diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index ca946d7791..e4bc1adbdf 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -135,7 +135,9 @@ DrawViewPart::DrawViewPart(void) : ADD_PROPERTY_TYPE(Source ,(0),group,App::Prop_None,"3D Shape to view"); Source.setScope(App::LinkScope::Global); ADD_PROPERTY_TYPE(Direction ,(0.0,-1.0,0.0), - group,App::Prop_None,"Projection direction. The direction you are looking from."); + group,App::Prop_None,"Projection Plane normal. The direction you are looking from."); + ADD_PROPERTY_TYPE(XDirection ,(0.0,0.0,0.0), + group,App::Prop_None,"Projection Plane X Axis in R3. Rotates/Mirrors View"); ADD_PROPERTY_TYPE(Perspective ,(false),group,App::Prop_None, "Perspective(true) or Orthographic(false) projection"); ADD_PROPERTY_TYPE(Focus,(defDist),group,App::Prop_None,"Perspective view focus distance"); @@ -239,26 +241,10 @@ App::DocumentObjectExecReturn *DrawViewPart::execute(void) return App::DocumentObject::StdReturn; } - gp_Pnt inputCenter; - Base::Vector3d stdOrg(0.0,0.0,0.0); + checkXDirection(); - inputCenter = TechDraw::findCentroid(shape, - getViewAxis(stdOrg,Direction.getValue())); - - - shapeCentroid = Base::Vector3d(inputCenter.X(),inputCenter.Y(),inputCenter.Z()); - TopoDS_Shape mirroredShape; - mirroredShape = TechDraw::mirrorShape(shape, - inputCenter, - getScale()); - - gp_Ax2 viewAxis = getViewAxis(shapeCentroid,Direction.getValue()); - if (!DrawUtil::fpCompare(Rotation.getValue(),0.0)) { - mirroredShape = TechDraw::rotateShape(mirroredShape, - viewAxis, - Rotation.getValue()); - } - geometryObject = buildGeometryObject(mirroredShape,viewAxis); + m_saveShape = shape; + geometryObject = makeGeometryForShape(shape); #if MOD_TECHDRAW_HANDLE_FACES auto start = std::chrono::high_resolution_clock::now(); @@ -318,6 +304,36 @@ void DrawViewPart::onChanged(const App::Property* prop) //TODO: when scale changes, any Dimensions for this View sb recalculated. DVD should pick this up subject to topological naming issues. } +GeometryObject* DrawViewPart::makeGeometryForShape(TopoDS_Shape shape) +{ +// Base::Console().Message("DVP::makeGeometryforShape() - %s\n", Label.getValue()); + gp_Pnt inputCenter; + Base::Vector3d stdOrg(0.0,0.0,0.0); + + gp_Ax2 viewAxis = getProjectionCS(stdOrg); + + inputCenter = TechDraw::findCentroid(shape, + viewAxis); + Base::Vector3d centroid(inputCenter.X(), + inputCenter.Y(), + inputCenter.Z()); + + //center shape on origin + TopoDS_Shape centeredShape = TechDraw::moveShape(shape, + centroid * -1.0); + + TopoDS_Shape scaledShape = TechDraw::scaleShape(centeredShape, + getScale()); + if (!DrawUtil::fpCompare(Rotation.getValue(),0.0)) { + scaledShape = TechDraw::rotateShape(scaledShape, + viewAxis, + Rotation.getValue()); + } +// BRepTools::Write(scaledShape, "DVPScaled.brep"); //debug + GeometryObject* go = buildGeometryObject(scaledShape,viewAxis); + return go; +} + //note: slightly different than routine with same name in DrawProjectSplit TechDraw::GeometryObject* DrawViewPart::buildGeometryObject(TopoDS_Shape shape, gp_Ax2 viewAxis) { @@ -327,9 +343,6 @@ TechDraw::GeometryObject* DrawViewPart::buildGeometryObject(TopoDS_Shape shape, go->setFocus(Focus.getValue()); go->usePolygonHLR(CoarseView.getValue()); - Base::Vector3d baseProjDir = Direction.getValue(); - saveParamSpace(baseProjDir); - if (go->usePolygonHLR()){ go->projectShapeWithPolygonAlgo(shape, viewAxis); @@ -400,7 +413,6 @@ void DrawViewPart::extractFaces() origEdges.push_back((*itEdge)->occEdge); } - std::vector faceEdges; std::vector nonZero; for (auto& e:origEdges) { //drop any zero edges (shouldn't be any by now!!!) @@ -702,22 +714,19 @@ QRectF DrawViewPart::getRect() const return result; } -//used to project pt (ex SectionOrigin) onto paper plane +//used to project a pt (ex SectionOrigin) onto paper plane Base::Vector3d DrawViewPart::projectPoint(const Base::Vector3d& pt) const { - gp_Trsf mirrorTransform; - mirrorTransform.SetMirror( gp_Ax2(gp_Pnt(shapeCentroid.x,shapeCentroid.y,shapeCentroid.z), - gp_Dir(0, -1, 0)) ); - gp_Pnt basePt(pt.x,pt.y,pt.z); - gp_Pnt mirrorGp = basePt.Transformed(mirrorTransform); - Base::Vector3d mirrorPt(mirrorGp.X(),mirrorGp.Y(), mirrorGp.Z()); - Base::Vector3d centeredPoint = mirrorPt - shapeCentroid; - Base::Vector3d direction = Direction.getValue(); - gp_Ax2 viewAxis = getViewAxis(centeredPoint,direction); + Base::Vector3d stdOrg(0.0,0.0,0.0); + gp_Ax2 viewAxis = getProjectionCS(stdOrg); + gp_Pnt gPt(pt.x,pt.y,pt.z); + HLRAlgo_Projector projector( viewAxis ); gp_Pnt2d prjPnt; - projector.Project(gp_Pnt(centeredPoint.x,centeredPoint.y,centeredPoint.z), prjPnt); - return Base::Vector3d(prjPnt.X(),prjPnt.Y(), 0.0); + projector.Project(gPt, prjPnt); + Base::Vector3d result(prjPnt.X(),prjPnt.Y(), 0.0); + result = DrawUtil::invertY(result); + return result; } bool DrawViewPart::hasGeometry(void) const @@ -737,30 +746,51 @@ bool DrawViewPart::hasGeometry(void) const return result; } -//boring here. gets more interesting in descendents. -gp_Ax2 DrawViewPart::getViewAxis(const Base::Vector3d& pt, - const Base::Vector3d& axis, - const bool flip) const +gp_Ax2 DrawViewPart::getProjectionCS(const Base::Vector3d pt) const { - gp_Ax2 viewAxis = TechDraw::getViewAxis(pt,axis,flip); - +// Base::Console().Message("DVP::getProjectionCS() - %s - %s\n", getNameInDocument(), Label.getValue()); + Base::Vector3d direction = Direction.getValue(); + gp_Dir gDir(direction.x, + direction.y, + direction.z); + Base::Vector3d xDir = getXDirection(); + gp_Dir gXDir(xDir.x, + xDir.y, + xDir.z); + gp_Pnt gOrg(pt.x, + pt.y, + pt.z); + gp_Ax2 viewAxis(gOrg, + gDir); + try { + viewAxis = gp_Ax2(gOrg, + gDir, + gXDir); + } + catch (...) { + Base::Console().Warning("DVP - %s - failed to create projection CS\n", getNameInDocument()); + } return viewAxis; } -void DrawViewPart::saveParamSpace(const Base::Vector3d& direction, const Base::Vector3d& xAxis) +gp_Ax2 DrawViewPart::getViewAxis(const Base::Vector3d& pt, + const Base::Vector3d& direction, + const bool flip) const { - (void)xAxis; - Base::Vector3d origin(0.0,0.0,0.0); - gp_Ax2 viewAxis = getViewAxis(origin,direction); - - gp_Dir xdir = viewAxis.XDirection(); - uDir = Base::Vector3d(xdir.X(),xdir.Y(),xdir.Z()); - gp_Dir ydir = viewAxis.YDirection(); - vDir = Base::Vector3d(ydir.X(),ydir.Y(),ydir.Z()); - wDir = Base::Vector3d(direction.x, -direction.y, direction.z); - wDir.Normalize(); + (void) direction; + (void) flip; + Base::Console().Message("DVP::getViewAxis - deprecated. Use getProjectionCS.\n"); + return getProjectionCS(pt); } +//TODO: make saveShape a property +Base::Vector3d DrawViewPart::getCentroid(void) const +{ + Base::Vector3d stdOrg(0.0,0.0,0.0); + Base::Vector3d centroid = TechDraw::findCentroidVec(m_saveShape, + getProjectionCS(stdOrg)); + return centroid; +} std::vector DrawViewPart::getSectionRefs(void) const { @@ -791,16 +821,6 @@ const std::vector DrawViewPart::getVisibleFaceEdges() con return geometryObject->getVisibleFaceEdges(SmoothVisible.getValue(),SeamVisible.getValue()); } -gp_Pln DrawViewPart::getProjPlane() const -{ - Base::Vector3d plnPnt(0.0,0.0,0.0); - Base::Vector3d plnNorm = Direction.getValue(); - gp_Ax2 viewAxis = getViewAxis(plnPnt,plnNorm,false); - gp_Ax3 viewAxis3(viewAxis); - - return gp_Pln(viewAxis3); -} - void DrawViewPart::getRunControl() { Base::Reference hGrp = App::GetApplication().GetUserParameter() @@ -890,6 +910,61 @@ bool DrawViewPart::isIso(void) const return result; } +bool DrawViewPart::checkXDirection(void) const +{ +// Base::Console().Message("DVP::checkXDirection()\n"); + Base::Vector3d xDir = XDirection.getValue(); + if (DrawUtil::fpCompare(xDir.Length(), 0.0)) { + Base::Vector3d dir = Direction.getValue(); + Base::Vector3d origin(0.0,0.0,0.0); + Base::Vector3d xDir = getLegacyX(origin, + dir); + Base::Console().Warning("DVP - %s - XDirection property not set. Try %s\n", + getNameInDocument(), + DrawUtil::formatVector(xDir).c_str()); + return false; + } + return true; +} + +// +Base::Vector3d DrawViewPart::getXDirection(void) const +{ +// Base::Console().Message("DVP::getXDirection() - %s\n", Label.getValue()); + Base::Vector3d result(1.0, 0.0, 0.0); //default X + App::Property* prop = getPropertyByName("XDirection"); + if (prop != nullptr) { //have an XDirection property + Base::Vector3d propVal = XDirection.getValue(); + if (DrawUtil::fpCompare(propVal.Length(), 0.0)) { //but it has no value + Base::Vector3d dir = Direction.getValue(); //make a sensible default + Base::Vector3d org(0.0, 0.0, 0.0); + result = getLegacyX(org, + dir); + } else { + result = propVal; //normal case. XDirection is set. + } + } else { //no Property. can this happen? + Base::Vector3d dir = Direction.getValue(); //make a sensible default + Base::Vector3d org(0.0, 0.0, 0.0); + result = getLegacyX(org, + dir); + } + return result; +} + +Base::Vector3d DrawViewPart::getLegacyX(const Base::Vector3d& pt, + const Base::Vector3d& axis, + const bool flip) const +{ +// gp_Ax2 viewAxis = TechDraw::getViewAxis(pt,axis,flip); + gp_Ax2 viewAxis = TechDraw::legacyViewAxis1(pt, axis, flip); + gp_Dir gXDir = viewAxis.XDirection(); + Base::Vector3d result(gXDir.X(), + gXDir.Y(), + gXDir.Z()); + return result; +} + //******** //* Cosmetics //******** diff --git a/src/Mod/TechDraw/App/DrawViewPart.h b/src/Mod/TechDraw/App/DrawViewPart.h index 99287cfdb4..9f965e826e 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.h +++ b/src/Mod/TechDraw/App/DrawViewPart.h @@ -93,6 +93,7 @@ public: App::PropertyLinkList Source; App::PropertyVector Direction; //TODO: Rename to YAxisDirection or whatever this actually is (ProjectionDirection) + App::PropertyVector XDirection; App::PropertyBool Perspective; App::PropertyDistance Focus; @@ -144,29 +145,31 @@ public: double getBoxX(void) const; double getBoxY(void) const; virtual QRectF getRect() const override; - virtual std::vector getSectionRefs() const; //are there ViewSections based on this ViewPart? + virtual std::vector getSectionRefs() const; //are there ViewSections based on this ViewPart? virtual std::vector getDetailRefs() const; - const Base::Vector3d& getUDir(void) const {return uDir;} //paperspace X - const Base::Vector3d& getVDir(void) const {return vDir;} //paperspace Y - const Base::Vector3d& getWDir(void) const {return wDir;} //paperspace Z - virtual const Base::Vector3d& getCentroid(void) const {return shapeCentroid;} - Base::Vector3d projectPoint(const Base::Vector3d& pt) const; + + + virtual Base::Vector3d projectPoint(const Base::Vector3d& pt) const; virtual gp_Ax2 getViewAxis(const Base::Vector3d& pt, const Base::Vector3d& direction, const bool flip=true) const; + virtual gp_Ax2 getProjectionCS(Base::Vector3d pt) const; + virtual Base::Vector3d getXDirection(void) const; //don't use XDirection.getValue() + virtual Base::Vector3d getCentroid(void) const; + virtual Base::Vector3d getLegacyX(const Base::Vector3d& pt, + const Base::Vector3d& axis, + const bool flip = true) const; + bool handleFaces(void); bool showSectionEdges(void); bool isUnsetting(void) { return nowUnsetting; } - gp_Pln getProjPlane(void) const; virtual std::vector getWireForFace(int idx) const; virtual TopoDS_Shape getSourceShape(void) const; -/* virtual std::vector getShapesFromObject(App::DocumentObject* docObj) const; */ virtual TopoDS_Shape getSourceShapeFused(void) const; -/* std::vector extractDrawableShapes(TopoDS_Shape shapeIn) const;*/ bool isIso(void) const; @@ -224,26 +227,27 @@ public: void dumpCosVerts(const std::string text); protected: + bool checkXDirection(void) const; + TechDraw::GeometryObject *geometryObject; Base::BoundBox3d bbox; virtual void onChanged(const App::Property* prop) override; virtual void unsetupObject() override; - virtual TechDraw::GeometryObject* buildGeometryObject(TopoDS_Shape shape, gp_Ax2 viewAxis); + virtual TechDraw::GeometryObject* buildGeometryObject(TopoDS_Shape shape, gp_Ax2 viewAxis); //const?? + virtual TechDraw::GeometryObject* makeGeometryForShape(TopoDS_Shape shape); //const?? + void extractFaces(); - //Projection parameter space - virtual void saveParamSpace(const Base::Vector3d& direction, const Base::Vector3d& xAxis=Base::Vector3d(0.0,0.0,0.0)); - Base::Vector3d uDir; //paperspace X - Base::Vector3d vDir; //paperspace Y - Base::Vector3d wDir; //paperspace Z Base::Vector3d shapeCentroid; void getRunControl(void); bool m_sectionEdges; bool m_handleFaces; + TopoDS_Shape m_saveShape; //TODO: make this a Property. Part::TopoShapeProperty?? + private: bool nowUnsetting; diff --git a/src/Mod/TechDraw/App/DrawViewSection.cpp b/src/Mod/TechDraw/App/DrawViewSection.cpp index a0e7507339..1d85411c0b 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.cpp +++ b/src/Mod/TechDraw/App/DrawViewSection.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -241,6 +242,8 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void) return new App::DocumentObjectExecReturn("BaseView Source object is Null"); } + checkXDirection(); + //is SectionOrigin valid? Bnd_Box centerBox; BRepBndLib::Add(baseShape, centerBox); @@ -252,13 +255,6 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void) if(!isReallyInBox(gp_Pnt(orgPnt.x,orgPnt.y,orgPnt.z), centerBox)) { Base::Console().Warning("DVS: SectionOrigin doesn't intersect part in %s\n",getNameInDocument()); -// Base::Console().Warning("DVS: Using center of bounding box.\n"); -// double Xmin,Ymin,Zmin,Xmax,Ymax,Zmax; -// centerBox.Get(Xmin,Ymin,Zmin,Xmax,Ymax,Zmax); -// orgPnt = Base::Vector3d((Xmax + Xmin)/2.0, -// (Ymax + Ymin)/2.0, -// (Zmax + Zmin)/2.0); -// SectionOrigin.setValue(orgPnt); } // Make the extrusion face @@ -296,36 +292,32 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void) return DrawView::execute(); } - m_cutShape = rawShape; -// m_cutShape = TechDraw::moveShape(m_cutShape, //centre on origin -// -SectionOrigin.getValue()); - if (debugSection()) { - BRepTools::Write(m_cutShape, "DVSMCut.brep"); //debug - } - - gp_Pnt inputCenter; gp_Ax2 viewAxis; + TopoDS_Shape centeredShape; try { - inputCenter = TechDraw::findCentroid(rawShape, - Direction.getValue()); - TopoDS_Shape scaledShape = TechDraw::scaleShape(rawShape, + Base::Vector3d sectionOrigin = SectionOrigin.getValue(); + centeredShape = TechDraw::moveShape(rawShape, + sectionOrigin * -1.0); + m_cutShape = centeredShape; + + TopoDS_Shape scaledShape = TechDraw::scaleShape(centeredShape, getScale()); - TopoDS_Shape mirroredShape = TechDraw::mirrorShape(scaledShape, - inputCenter, - 1.0); -// getScale()); - viewAxis = getSectionCS(SectionDirection.getValueAsString()); + + Base::Vector3d origin(0.0, 0.0, 0.0); + viewAxis = getProjectionCS(origin); + if (!DrawUtil::fpCompare(Rotation.getValue(),0.0)) { - mirroredShape = TechDraw::rotateShape(mirroredShape, - viewAxis, - Rotation.getValue()); + scaledShape = TechDraw::rotateShape(scaledShape, + viewAxis, + Rotation.getValue()); } if (debugSection()) { + BRepTools::Write(m_cutShape, "DVSmCutShape.brep"); //debug BRepTools::Write(scaledShape, "DVSScaled.brep"); //debug - BRepTools::Write(mirroredShape, "DVSMirror.brep"); //debug - DrawUtil::dumpCS("DVS::execute - CS to GO", viewAxis); +// DrawUtil::dumpCS("DVS::execute - CS to GO", viewAxis); } - geometryObject = buildGeometryObject(mirroredShape,viewAxis); + + geometryObject = buildGeometryObject(scaledShape,viewAxis); #if MOD_TECHDRAW_HANDLE_FACES extractFaces(); @@ -338,33 +330,55 @@ App::DocumentObjectExecReturn *DrawViewSection::execute(void) } try { + //sectionFaces = build sectionFaces(rawShape); TopoDS_Compound sectionCompound = findSectionPlaneIntersections(rawShape); - TopoDS_Shape mirroredSection = TechDraw::mirrorShape(sectionCompound, - inputCenter, - getScale()); + + Base::Vector3d sectionOrigin = SectionOrigin.getValue(); + TopoDS_Shape centeredShape = TechDraw::moveShape(sectionCompound, + sectionOrigin * -1.0); + + TopoDS_Shape scaledSection = TechDraw::scaleShape(centeredShape, + getScale()); if (!DrawUtil::fpCompare(Rotation.getValue(),0.0)) { - mirroredSection = TechDraw::rotateShape(mirroredSection, - viewAxis, - Rotation.getValue()); + scaledSection = TechDraw::rotateShape(scaledSection, + viewAxis, + Rotation.getValue()); + } + if (debugSection()) { + BRepTools::Write(scaledSection, "DVSScaledFaces.brep"); //debug } sectionFaceWires.clear(); TopoDS_Compound newFaces; BRep_Builder builder; builder.MakeCompound(newFaces); - TopExp_Explorer expl(mirroredSection, TopAbs_FACE); + TopExp_Explorer expl(scaledSection, TopAbs_FACE); int idb = 0; for (; expl.More(); expl.Next()) { const TopoDS_Face& face = TopoDS::Face(expl.Current()); TopoDS_Face pFace = projectFace(face, - inputCenter, - Direction.getValue()); - if (!pFace.IsNull()) { - builder.Add(newFaces,pFace); - sectionFaceWires.push_back(ShapeAnalysis::OuterWire(pFace)); - } - idb++; + viewAxis); + if (!pFace.IsNull()) { + if (debugSection()) { + std::stringstream ss; + ss << "DVSScaledFace" << idb << ".brep" ; + std::string faceName = ss.str(); + BRepTools::Write(pFace, faceName.c_str()); //debug + } + TopoDS_Wire ow = ShapeAnalysis::OuterWire(pFace); +// BRepTools::Write(ow, "outerwire.brep"); //debug + //this check helps prevent "ghost" faces + BRepCheck_Wire chkWire(ow); + TopoDS_Edge e1, e2; + BRepCheck_Status status = chkWire.SelfIntersect(pFace, e1, e2); + if (status == BRepCheck_NoError) { + builder.Add(newFaces,pFace); + sectionFaceWires.push_back(ShapeAnalysis::OuterWire(pFace)); + } + } + idb++; } + //return newFaces; sectionFaces = newFaces; } catch (Standard_Failure& e2) { @@ -452,27 +466,15 @@ std::vector DrawViewSection::getFaceGeometry() //! project a single face using HLR - used for section faces TopoDS_Face DrawViewSection::projectFace(const TopoDS_Shape &face, - gp_Pnt faceCenter, - const Base::Vector3d &direction) + const gp_Ax2 CS) { - (void) direction; +// Base::Console().Message("DVS::projectFace()\n"); if(face.IsNull()) { throw Base::ValueError("DrawViewSection::projectFace - input Face is NULL"); } - Base::Vector3d origin(faceCenter.X(),faceCenter.Y(),faceCenter.Z()); - gp_Ax2 viewAxis = getSectionCS(SectionDirection.getValueAsString()); + TopoDS_Shape hardEdges = geometryObject->projectFace(face, CS); - HLRBRep_Algo *brep_hlr = new HLRBRep_Algo(); - brep_hlr->Add(face); - HLRAlgo_Projector projector( viewAxis ); - brep_hlr->Projector(projector); - brep_hlr->Update(); - brep_hlr->Hide(); - - HLRBRep_HLRToShape hlrToShape(brep_hlr); - TopoDS_Shape hardEdges = hlrToShape.VCompound(); -// TopoDS_Shape outEdges = hlrToShape.OutLineVCompound(); std::vector faceEdges; TopExp_Explorer expl(hardEdges, TopAbs_EDGE); int i; @@ -569,6 +571,7 @@ bool DrawViewSection::isReallyInBox (const gp_Pnt p, const Bnd_Box& bb) const void DrawViewSection::setCSFromBase(const std::string sectionName) { +// Base::Console().Message("DVS::setCSFromBase(%s)\n", sectionName.c_str()); gp_Ax2 CS = getCSFromBase(sectionName); gp_Dir gDir = CS.Direction(); Base::Vector3d vDir(gDir.X(), @@ -576,6 +579,11 @@ void DrawViewSection::setCSFromBase(const std::string sectionName) gDir.Z()); Direction.setValue(vDir); SectionNormal.setValue(vDir); + gp_Dir gxDir = CS.XDirection(); + Base::Vector3d vXDir(gxDir.X(), + gxDir.Y(), + gxDir.Z()); + XDirection.setValue(vXDir); } gp_Ax2 DrawViewSection::getCSFromBase(const std::string sectionName) @@ -584,189 +592,79 @@ gp_Ax2 DrawViewSection::getCSFromBase(const std::string sectionName) Base::Vector3d sectionNormal; Base::Vector3d sectionXDir; Base::Vector3d origin(0.0, 0.0, 0.0); - Base::Vector3d dvpDir = getBaseDVP()->Direction.getValue(); - gp_Ax2 dvpCS = getBaseDVP()->getViewAxis(origin, - dvpDir); -// flip); //what to do with this!?? + Base::Vector3d sectOrigin = SectionOrigin.getValue(); + + gp_Ax2 dvpCS = getBaseDVP()->getProjectionCS(sectOrigin); if (debugSection()) { - DrawUtil::dumpCS("DVS::getCSFromBase - dvp VA", dvpCS); + DrawUtil::dumpCS("DVS::getCSFromBase - dvp CS", dvpCS); } + gp_Dir dvpDir = dvpCS.Direction(); gp_Dir dvpUp = dvpCS.YDirection(); gp_Dir dvpRight = dvpCS.XDirection(); - Base::Vector3d dir = getBaseDVP()->Direction.getValue(); - Base::Vector3d up(dvpUp.X(), dvpUp.Y(), dvpUp.Z()); - Base::Vector3d right(dvpRight.X(), dvpRight.Y(), dvpRight.Z()); + gp_Pnt dvsLoc(sectOrigin.x, + sectOrigin.y, + sectOrigin.z); + gp_Dir dvsDir; + gp_Dir dvsXDir; - if (sectionName == "Up") { -// sectionNormal = up * -1.0; - sectionNormal = up; - sectionXDir = right; // + if (sectionName == "Up") { //looking up + dvsDir = dvpUp.Reversed(); + dvsXDir = dvpRight; } else if (sectionName == "Down") { -// sectionNormal = up; - sectionNormal = up * -1.0; - sectionXDir = right; + dvsDir = dvpUp; + dvsXDir = dvpRight; } else if (sectionName == "Left") { - sectionNormal = right; - sectionXDir = dir * -1.0; + dvsDir = dvpRight; + dvsXDir = dvpDir.Reversed(); } else if (sectionName == "Right") { - sectionNormal = right * -1.0; - sectionXDir = dir; + dvsDir = dvpRight.Reversed(); + dvsXDir = dvpDir; } else { Base::Console().Log("Error - DVS::getCSFromBase - bad sectionName: %s\n",sectionName.c_str()); - sectionNormal = right; - sectionXDir = dir; + dvsDir = dvpRight; + dvsXDir = dvpDir; } - gp_Dir dvsDir(sectionNormal.x, - sectionNormal.y, - sectionNormal.z); - gp_Dir dvsXDir(sectionXDir.x, - sectionXDir.y, - sectionXDir.z); - gp_Pnt dvsLoc(0.0, 0.0, 0.0); gp_Ax2 CS(dvsLoc, dvsDir, dvsXDir); + if (debugSection()) { DrawUtil::dumpCS("DVS::getCSFromBase - sectionCS out", CS); } + return CS; } - - -//! calculate the section Normal/Projection Direction given section name -//TODO: this should take base view rotation into account. -Base::Vector3d DrawViewSection::getSectionVector (const std::string sectionName) -{ -// Base::Console().Message("DVS::getSectionVector(%s) - %s\n", sectionName.c_str(), getNameInDocument()); - Base::Vector3d result; - Base::Vector3d stdX(1.0,0.0,0.0); - Base::Vector3d stdY(0.0,1.0,0.0); - Base::Vector3d stdZ(0.0,0.0,1.0); - - Base::Vector3d view = getBaseDVP()->Direction.getValue(); - view.Normalize(); - Base::Vector3d left = view.Cross(stdZ); - left.Normalize(); - Base::Vector3d up = view.Cross(left); - up.Normalize(); - double dot = view.Dot(stdZ); - - if (sectionName == "Up") { - result = up; - if (DrawUtil::fpCompare(dot,1.0)) { //view = stdZ - result = (-1.0 * stdY); - } else if (DrawUtil::fpCompare(dot,-1.0)) { //view = -stdZ - result = stdY; - } - } else if (sectionName == "Down") { - result = up * -1.0; - if (DrawUtil::fpCompare(dot,1.0)) { //view = stdZ - result = stdY; - } else if (DrawUtil::fpCompare(dot, -1.0)) { //view = -stdZ - result = (-1.0 * stdY); - } - } else if (sectionName == "Left") { - result = left * -1.0; - if (DrawUtil::fpCompare(fabs(dot),1.0)) { //view = +/- stdZ - result = stdX; - } - } else if (sectionName == "Right") { - result = left; - if (DrawUtil::fpCompare(fabs(dot),1.0)) { - result = -1.0 * stdX; - } - } else { - Base::Console().Log("Error - DVS::getSectionVector - bad sectionName: %s\n",sectionName.c_str()); - result = stdZ; - } - return result; -} - //returns current section cs gp_Ax2 DrawViewSection::getSectionCS(void) const { - std::string dirName = SectionDirection.getValueAsString(); - return getSectionCS(dirName); -} - -//! calculate the section Projection CS given section direction name -gp_Ax2 DrawViewSection::getSectionCS (const std::string dirName) const -{ - Base::Vector3d view = getBaseDVP()->Direction.getValue(); - view.Normalize(); - - Base::Vector3d sectionOrg = SectionOrigin.getValue(); - gp_Ax2 baseCS = getBaseDVP()->getViewAxis(sectionOrg, - view); - - // cardinal: 0 - left, 1 - right, 2 - up, 3 - down - int cardinal = 0; - if (dirName == "Up") { - cardinal = 2; - } else if (dirName == "Down") { - cardinal = 3; - } else if (dirName == "Left") { - cardinal = 0; - } else if (dirName == "Right") { - cardinal = 1; +// Base::Console().Message("DVS::getSectionCS()\n"); + Base::Vector3d vNormal = SectionNormal.getValue(); + gp_Dir gNormal(vNormal.x, + vNormal.y, + vNormal.z); + Base::Vector3d vXDir = getXDirection(); + gp_Dir gXDir(vXDir.x, + vXDir.y, + vXDir.z); + Base::Vector3d vOrigin = SectionOrigin.getValue(); + gp_Pnt gOrigin(vOrigin.x, + vOrigin.y, + vOrigin.z); + gp_Ax2 sectionCS(gOrigin, + gNormal); + try { + sectionCS = gp_Ax2(gOrigin, + gNormal, + gXDir); } - gp_Ax2 newCS = rotateCSCardinal(baseCS, cardinal); - return newCS; -} - - -//TODO: this should be able to handle arbitrary rotation of the CS -//TODO: this is useful beyond DVS. move to GO or DU or ??? -// or at least static in DVS. doesn't depend on DVS object -gp_Ax2 DrawViewSection::rotateCSCardinal(gp_Ax2 oldCS, int cardinal) const -{ - // cardinal: 0 - left, 1 - right, 2 - up, 3 - down - // as in DVS::SectionDirection - gp_Pnt oldOrg = oldCS.Location(); - gp_Dir oldMain = oldCS.Direction(); - gp_Dir oldX = oldCS.XDirection(); - - gp_Ax1 rotAxis; - gp_Dir crossed; - gp_Ax2 newCS; - double angle; - - //Note: cardinal refers to the the motion of the viewer's head. When the head turns to - // the left, the "Direction" moves to the right! When the viewer's head moves to look up, - // the "Direction" moves down! - - switch (cardinal) { - case 0: //right - crossed = oldMain.Crossed(oldX); - rotAxis = gp_Ax1(oldOrg, crossed); - angle = 90.0 * M_PI / 180.0; - newCS = oldCS.Rotated(rotAxis, angle); - break; - case 1: //left - crossed = oldMain.Crossed(oldX); - rotAxis = gp_Ax1(oldOrg, crossed); - angle = -90.0 * M_PI / 180.0; - newCS = oldCS.Rotated(rotAxis, angle); - break; - case 2: // head looks up, so Direction(projection normal) points down - rotAxis = gp_Ax1(oldOrg, oldX); - angle = -90.0 * M_PI / 180.0; - newCS = oldCS.Rotated(rotAxis, angle); - break; - case 3: //down - rotAxis = gp_Ax1(oldOrg, oldX); //one of these should be -oldX? - angle = 90.0 * M_PI / 180.0; - newCS = oldCS.Rotated(rotAxis, angle); - break; - default: - newCS = oldCS; - break; + catch (...) { + Base::Console().Warning("DVS::getSectionCS - %s - failed to create section CS\n", getNameInDocument()); } - return newCS; + return sectionCS; } gp_Ax2 DrawViewSection::rotateCSArbitrary(gp_Ax2 oldCS, diff --git a/src/Mod/TechDraw/App/DrawViewSection.h b/src/Mod/TechDraw/App/DrawViewSection.h index f946ab57a4..a1b02c5987 100644 --- a/src/Mod/TechDraw/App/DrawViewSection.h +++ b/src/Mod/TechDraw/App/DrawViewSection.h @@ -90,15 +90,12 @@ public: public: std::vector getFaceGeometry(); - Base::Vector3d getSectionVector (const std::string sectionName); void setCSFromBase(const std::string sectionName); gp_Ax2 getCSFromBase(const std::string sectionName); - gp_Ax2 rotateCSCardinal(gp_Ax2 oldCS, int cardinal) const; gp_Ax2 rotateCSArbitrary(gp_Ax2 oldCS, Base::Vector3d axis, double degAngle) const; - gp_Ax2 getSectionCS(const std::string dirName) const; gp_Ax2 getSectionCS() const; TechDraw::DrawViewPart* getBaseDVP() const; @@ -125,8 +122,8 @@ protected: gp_Pln getSectionPlane() const; TopoDS_Compound findSectionPlaneIntersections(const TopoDS_Shape& shape); TopoDS_Face projectFace(const TopoDS_Shape &face, - gp_Pnt faceCenter, - const Base::Vector3d &direction); + const gp_Ax2 CS); + void getParameters(void); bool debugSection(void) const; diff --git a/src/Mod/TechDraw/App/GeometryObject.cpp b/src/Mod/TechDraw/App/GeometryObject.cpp index 549e70a2fc..2d7828c1c8 100644 --- a/src/Mod/TechDraw/App/GeometryObject.cpp +++ b/src/Mod/TechDraw/App/GeometryObject.cpp @@ -24,6 +24,7 @@ #ifndef _PreComp_ #include +#include #include #include #include @@ -161,9 +162,10 @@ void GeometryObject::clear() void GeometryObject::projectShape(const TopoDS_Shape& input, const gp_Ax2 viewAxis) { -// Base::Console().Message("GO::projectShape()\n"); +// Base::Console().Message("GO::projectShape() - %s\n", m_parentName.c_str()); // Clear previous Geometry clear(); +// DrawUtil::dumpCS("GO::projectShape - VA in", viewAxis); //debug auto start = chrono::high_resolution_clock::now(); @@ -173,11 +175,9 @@ void GeometryObject::projectShape(const TopoDS_Shape& input, brep_hlr->Add(input, m_isoCount); if (m_isPersp) { double fLength = std::max(Precision::Confusion(),m_focus); -// HLRAlgo_Projector projector( projAxis, fLength ); HLRAlgo_Projector projector( viewAxis, fLength ); brep_hlr->Projector(projector); } else { -// HLRAlgo_Projector projector( projAxis ); HLRAlgo_Projector projector( viewAxis ); brep_hlr->Projector(projector); } @@ -191,7 +191,6 @@ void GeometryObject::projectShape(const TopoDS_Shape& input, } catch (...) { throw Base::RuntimeError("GeometryObject::projectShape - unknown error occurred while projecting shape"); -// Standard_Failure::Raise("GeometryObject::projectShape - error occurred while projecting shape"); } auto end = chrono::high_resolution_clock::now(); @@ -205,27 +204,47 @@ void GeometryObject::projectShape(const TopoDS_Shape& input, HLRBRep_HLRToShape hlrToShape(brep_hlr); visHard = hlrToShape.VCompound(); - visSmooth = hlrToShape.Rg1LineVCompound(); - visSeam = hlrToShape.RgNLineVCompound(); - visOutline = hlrToShape.OutLineVCompound(); - visIso = hlrToShape.IsoLineVCompound(); - hidHard = hlrToShape.HCompound(); - hidSmooth = hlrToShape.Rg1LineHCompound(); - hidSeam = hlrToShape.RgNLineHCompound(); - hidOutline = hlrToShape.OutLineHCompound(); - hidIso = hlrToShape.IsoLineHCompound(); - -//need these 3d curves to prevent "zero edges" later BRepLib::BuildCurves3d(visHard); + visHard = invertGeometry(visHard); +// BRepTools::Write(visHard, "GOvisHardi.brep"); //debug + + visSmooth = hlrToShape.Rg1LineVCompound(); BRepLib::BuildCurves3d(visSmooth); + visSmooth = invertGeometry(visSmooth); + + visSeam = hlrToShape.RgNLineVCompound(); BRepLib::BuildCurves3d(visSeam); + visSeam = invertGeometry(visSeam); + + visOutline = hlrToShape.OutLineVCompound(); BRepLib::BuildCurves3d(visOutline); + visOutline = invertGeometry(visOutline); + + visIso = hlrToShape.IsoLineVCompound(); BRepLib::BuildCurves3d(visIso); + visIso = invertGeometry(visIso); + + hidHard = hlrToShape.HCompound(); BRepLib::BuildCurves3d(hidHard); + hidHard = invertGeometry(hidHard); +// BRepTools::Write(hidHard, "GOhidHardi.brep"); //debug + + hidSmooth = hlrToShape.Rg1LineHCompound(); BRepLib::BuildCurves3d(hidSmooth); + hidSmooth = invertGeometry(hidSmooth); + + hidSeam = hlrToShape.RgNLineHCompound(); BRepLib::BuildCurves3d(hidSeam); + hidSeam = invertGeometry(hidSeam); + + hidOutline = hlrToShape.OutLineHCompound(); BRepLib::BuildCurves3d(hidOutline); + hidOutline = invertGeometry(hidOutline); + + hidIso = hlrToShape.IsoLineHCompound(); BRepLib::BuildCurves3d(hidIso); + hidIso = invertGeometry(hidIso); + } catch (const Standard_Failure& e) { Base::Console().Error("GO::projectShape - OCC error - %s - while extracting edges\n", @@ -240,6 +259,26 @@ void GeometryObject::projectShape(const TopoDS_Shape& input, Base::Console().Log("TIMING - %s GO spent: %.3f millisecs in hlrToShape and BuildCurves\n",m_parentName.c_str(),diffOut); } +//mirror a shape thru XZ plane for Qt's inverted Y coordinate +TopoDS_Shape GeometryObject::invertGeometry(const TopoDS_Shape s) +{ + TopoDS_Shape result; + if (s.IsNull()) { + result = s; + return result; + } + + gp_Trsf mirrorY; + gp_Pnt org(0.0, 0.0, 0.0); + gp_Dir Y(0.0, 1.0, 0.0); + gp_Ax2 mirrorPlane(org, + Y); + mirrorY.SetMirror(mirrorPlane); + BRepBuilderAPI_Transform mkTrf(s, mirrorY, true); + result = mkTrf.Shape(); + return result; +} + //!set up a hidden line remover and project a shape with it void GeometryObject::projectShapeWithPolygonAlgo(const TopoDS_Shape& input, const gp_Ax2 viewAxis) @@ -300,24 +339,39 @@ void GeometryObject::projectShapeWithPolygonAlgo(const TopoDS_Shape& input, HLRBRep_PolyHLRToShape polyhlrToShape; polyhlrToShape.Update(brep_hlrPoly); - visHard = polyhlrToShape.VCompound(); - visSmooth = polyhlrToShape.Rg1LineVCompound(); - visSeam = polyhlrToShape.RgNLineVCompound(); - visOutline = polyhlrToShape.OutLineVCompound(); - hidHard = polyhlrToShape.HCompound(); - hidSmooth = polyhlrToShape.Rg1LineHCompound(); - hidSeam = polyhlrToShape.RgNLineHCompound(); - hidOutline = polyhlrToShape.OutLineHCompound(); - - //need these 3d curves to prevent "zero edges" later + visHard = polyhlrToShape.VCompound(); BRepLib::BuildCurves3d(visHard); + visHard = invertGeometry(visHard); +// BRepTools::Write(visHard, "GOvisHardi.brep"); //debug + + visSmooth = polyhlrToShape.Rg1LineVCompound(); BRepLib::BuildCurves3d(visSmooth); + visSmooth = invertGeometry(visSmooth); + + visSeam = polyhlrToShape.RgNLineVCompound(); BRepLib::BuildCurves3d(visSeam); + visSeam = invertGeometry(visSeam); + + visOutline = polyhlrToShape.OutLineVCompound(); BRepLib::BuildCurves3d(visOutline); + visOutline = invertGeometry(visOutline); + + hidHard = polyhlrToShape.HCompound(); BRepLib::BuildCurves3d(hidHard); + hidHard = invertGeometry(hidHard); +// BRepTools::Write(hidHard, "GOhidHardi.brep"); //debug + + hidSmooth = polyhlrToShape.Rg1LineHCompound(); BRepLib::BuildCurves3d(hidSmooth); + hidSmooth = invertGeometry(hidSmooth); + + hidSeam = polyhlrToShape.RgNLineHCompound(); BRepLib::BuildCurves3d(hidSeam); + hidSeam = invertGeometry(hidSeam); + + hidOutline = polyhlrToShape.OutLineHCompound(); BRepLib::BuildCurves3d(hidOutline); + hidOutline = invertGeometry(hidOutline); } catch (const Standard_Failure& e) { Base::Console().Error("GO::projectShapeWithPolygonAlgo - OCC error - %s - while extracting edges\n", @@ -333,6 +387,29 @@ void GeometryObject::projectShapeWithPolygonAlgo(const TopoDS_Shape& input, Base::Console().Log("TIMING - %s GO spent: %.3f millisecs in HLRBRep_PolyAlgo & co\n", m_parentName.c_str(), diffOut); } +TopoDS_Shape GeometryObject::projectFace(const TopoDS_Shape &face, + const gp_Ax2 CS) +{ +// Base::Console().Message("GO::projectFace()\n"); + if(face.IsNull()) { + throw Base::ValueError("GO::projectFace - input Face is NULL"); + } + + HLRBRep_Algo *brep_hlr = new HLRBRep_Algo(); + brep_hlr->Add(face); + HLRAlgo_Projector projector( CS ); + brep_hlr->Projector(projector); + brep_hlr->Update(); + brep_hlr->Hide(); + + HLRBRep_HLRToShape hlrToShape(brep_hlr); + TopoDS_Shape hardEdges = hlrToShape.VCompound(); + BRepLib::BuildCurves3d(hardEdges); + hardEdges = invertGeometry(hardEdges); + + return hardEdges; +} + //!add edges meeting filter criteria for category, visibility void GeometryObject::extractGeometry(edgeClass category, bool hlrVisible) { @@ -655,7 +732,55 @@ gp_Ax2 TechDraw::getViewAxis(const Base::Vector3d origin, const Base::Vector3d& direction, const bool flip) { +// Base::Console().Message("GO::getViewAxis() - 1 - use only with getLegacyX\n"); (void) flip; + gp_Ax2 viewAxis; + gp_Pnt inputCenter(origin.x,origin.y,origin.z); + Base::Vector3d stdZ(0.0,0.0,1.0); + Base::Vector3d stdOrg(0.0,0.0,0.0); + Base::Vector3d cross = direction; + if (TechDraw::DrawUtil::checkParallel(direction, stdZ)) { + cross = Base::Vector3d(1.0,0.0,0.0); + } else { + cross.Normalize(); + cross = cross.Cross(stdZ); + } + + if (cross.IsEqual(stdOrg,FLT_EPSILON)) { + viewAxis = gp_Ax2(inputCenter, + gp_Dir(direction.x, direction.y, direction.z)); + return viewAxis; + } + + viewAxis = gp_Ax2(inputCenter, + gp_Dir(direction.x, direction.y, direction.z), + gp_Dir(cross.x, cross.y, cross.z)); + return viewAxis; +} + +//! gets a coordinate system specified by Z and X directions +//getViewAxis 2 +gp_Ax2 TechDraw::getViewAxis(const Base::Vector3d origin, + const Base::Vector3d& direction, + const Base::Vector3d& xAxis, + const bool flip) +{ +// Base::Console().Message("GO::getViewAxis() - 2\n"); + (void) flip; + gp_Pnt inputCenter(origin.x,origin.y,origin.z); + gp_Ax2 viewAxis; + viewAxis = gp_Ax2(inputCenter, + gp_Dir(direction.x, direction.y, direction.z), + gp_Dir(xAxis.x, xAxis.y, xAxis.z)); + return viewAxis; +} + +// was getViewAxis 1 +// getViewAxis as used before XDirection property adopted +gp_Ax2 TechDraw::legacyViewAxis1(const Base::Vector3d origin, + const Base::Vector3d& direction, + const bool flip) +{ gp_Ax2 viewAxis; gp_Pnt inputCenter(origin.x,origin.y,origin.z); Base::Vector3d stdZ(0.0,0.0,1.0); @@ -685,30 +810,11 @@ gp_Ax2 TechDraw::getViewAxis(const Base::Vector3d origin, return viewAxis; } -//! gets a coordinate system specified by Z and X directions -//getViewAxis 2 -gp_Ax2 TechDraw::getViewAxis(const Base::Vector3d origin, - const Base::Vector3d& direction, - const Base::Vector3d& xAxis, - const bool flip) -{ - (void) flip; - gp_Pnt inputCenter(origin.x,origin.y,origin.z); - Base::Vector3d flipDirection(direction.x,-direction.y,direction.z); - if (!flip) { - flipDirection = Base::Vector3d(direction.x,direction.y,direction.z); - } - gp_Ax2 viewAxis; - viewAxis = gp_Ax2(inputCenter, - gp_Dir(flipDirection.x, flipDirection.y, flipDirection.z), - gp_Dir(xAxis.x, xAxis.y, xAxis.z)); - return viewAxis; -} - //! Returns the centroid of shape, as viewed according to direction gp_Pnt TechDraw::findCentroid(const TopoDS_Shape &shape, const Base::Vector3d &direction) { +// Base::Console().Message("GO::findCentroid() - 1\n"); Base::Vector3d origin(0.0,0.0,0.0); gp_Ax2 viewAxis = getViewAxis(origin,direction); return findCentroid(shape,viewAxis); @@ -718,6 +824,7 @@ gp_Pnt TechDraw::findCentroid(const TopoDS_Shape &shape, gp_Pnt TechDraw::findCentroid(const TopoDS_Shape &shape, const gp_Ax2 viewAxis) { +// Base::Console().Message("GO::findCentroid() - 2\n"); // Base::Vector3d origin(0.0,0.0,0.0); // gp_Ax2 viewAxis = getViewAxis(origin,direction); @@ -745,11 +852,22 @@ gp_Pnt TechDraw::findCentroid(const TopoDS_Shape &shape, Base::Vector3d TechDraw::findCentroidVec(const TopoDS_Shape &shape, const Base::Vector3d &direction) { +// Base::Console().Message("GO::findCentroidVec() - 1\n"); gp_Pnt p = TechDraw::findCentroid(shape,direction); Base::Vector3d result(p.X(),p.Y(),p.Z()); return result; } +Base::Vector3d TechDraw::findCentroidVec(const TopoDS_Shape &shape, + const gp_Ax2 cs) +{ +// Base::Console().Message("GO::findCentroidVec() - 2\n"); + gp_Pnt p = TechDraw::findCentroid(shape,cs); + Base::Vector3d result(p.X(),p.Y(),p.Z()); + return result; +} + + //!scales & mirrors a shape about a center TopoDS_Shape TechDraw::mirrorShape(const TopoDS_Shape &input, const gp_Pnt& inputCenter, @@ -831,7 +949,7 @@ TopoDS_Shape TechDraw::scaleShape(const TopoDS_Shape &input, //!moves a shape TopoDS_Shape TechDraw::moveShape(const TopoDS_Shape &input, - const Base::Vector3d& motion) + const Base::Vector3d& motion) { TopoDS_Shape transShape; try { diff --git a/src/Mod/TechDraw/App/GeometryObject.h b/src/Mod/TechDraw/App/GeometryObject.h index 38163831af..d67db14632 100644 --- a/src/Mod/TechDraw/App/GeometryObject.h +++ b/src/Mod/TechDraw/App/GeometryObject.h @@ -78,6 +78,8 @@ gp_Pnt TechDrawExport findCentroid(const TopoDS_Shape &shape, const gp_Ax2 viewAxis); Base::Vector3d TechDrawExport findCentroidVec(const TopoDS_Shape &shape, const Base::Vector3d &direction); +Base::Vector3d TechDrawExport findCentroidVec(const TopoDS_Shape &shape, + const gp_Ax2 cs); gp_Ax2 TechDrawExport getViewAxis(const Base::Vector3d origin, const Base::Vector3d& direction, @@ -86,6 +88,9 @@ gp_Ax2 TechDrawExport getViewAxis(const Base::Vector3d origin, const Base::Vector3d& direction, const Base::Vector3d& xAxis, const bool flip=true); +gp_Ax2 TechDrawExport legacyViewAxis1(const Base::Vector3d origin, + const Base::Vector3d& direction, + const bool flip=true); class TechDrawExport GeometryObject { @@ -108,6 +113,8 @@ public: const gp_Ax2 viewAxis); void projectShapeWithPolygonAlgo(const TopoDS_Shape &input, const gp_Ax2 viewAxis); + TopoDS_Shape projectFace(const TopoDS_Shape &face, + const gp_Ax2 CS); void extractGeometry(edgeClass category, bool visible); void addFaceGeom(Face * f); @@ -121,6 +128,7 @@ public: void setFocus(double f) { m_focus = f; } double getFocus(void) { return m_focus; } void pruneVertexGeom(Base::Vector3d center, double radius); + TopoDS_Shape invertGeometry(const TopoDS_Shape s); TopoDS_Shape getVisHard(void) { return visHard; } TopoDS_Shape getVisOutline(void) { return visOutline; } diff --git a/src/Mod/TechDraw/Gui/Command.cpp b/src/Mod/TechDraw/Gui/Command.cpp index b95d0ce0f7..8a40ab7294 100644 --- a/src/Mod/TechDraw/Gui/Command.cpp +++ b/src/Mod/TechDraw/Gui/Command.cpp @@ -354,6 +354,10 @@ void CmdTechDrawView::activated(int iMsg) getDocument()->setStatus(App::Document::Status::SkipRecompute, true); doCommand(Doc,"App.activeDocument().%s.Direction = FreeCAD.Vector(%.3f,%.3f,%.3f)", FeatName.c_str(), projDir.x,projDir.y,projDir.z); + //do something clever with dirs.second; +// dvp->setXDir(dirs.second); + doCommand(Doc,"App.activeDocument().%s.XDirection = FreeCAD.Vector(%.3f,%.3f,%.3f)", + FeatName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z); doCommand(Doc,"App.activeDocument().%s.recompute()", FeatName.c_str()); getDocument()->setStatus(App::Document::Status::SkipRecompute, false); } else { @@ -362,6 +366,9 @@ void CmdTechDrawView::activated(int iMsg) getDocument()->setStatus(App::Document::Status::SkipRecompute, true); doCommand(Doc,"App.activeDocument().%s.Direction = FreeCAD.Vector(%.3f,%.3f,%.3f)", FeatName.c_str(), projDir.x,projDir.y,projDir.z); + doCommand(Doc,"App.activeDocument().%s.XDirection = FreeCAD.Vector(%.3f,%.3f,%.3f)", + FeatName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z); +// dvp->setXDir(dirs.second); getDocument()->setStatus(App::Document::Status::SkipRecompute, false); doCommand(Doc,"App.activeDocument().%s.recompute()", FeatName.c_str()); } @@ -527,6 +534,7 @@ void CmdTechDrawDetailView::activated(int iMsg) doCommand(Doc,"App.activeDocument().%s.BaseView = App.activeDocument().%s",FeatName.c_str(),dvp->getNameInDocument()); doCommand(Doc,"App.activeDocument().%s.Direction = App.activeDocument().%s.Direction",FeatName.c_str(),dvp->getNameInDocument()); + doCommand(Doc,"App.activeDocument().%s.XDirection = App.activeDocument().%s.XDirection",FeatName.c_str(),dvp->getNameInDocument()); doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),FeatName.c_str()); updateActive(); //ok here, no preceding recompute @@ -635,6 +643,8 @@ void CmdTechDrawProjectionGroup::activated(int iMsg) multiViewName.c_str(), dirs.first.x,dirs.first.y,dirs.first.z); doCommand(Doc,"App.activeDocument().%s.Anchor.RotationVector = FreeCAD.Vector(%.3f,%.3f,%.3f)", multiViewName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z); + doCommand(Doc,"App.activeDocument().%s.Anchor.XDirection = FreeCAD.Vector(%.3f,%.3f,%.3f)", + multiViewName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z); getDocument()->setStatus(App::Document::Status::SkipRecompute, false); } else { std::pair dirs = DrawGuiUtil::get3DDirAndRot(); @@ -643,6 +653,8 @@ void CmdTechDrawProjectionGroup::activated(int iMsg) multiViewName.c_str(), dirs.first.x,dirs.first.y,dirs.first.z); doCommand(Doc,"App.activeDocument().%s.Anchor.RotationVector = FreeCAD.Vector(%.3f,%.3f,%.3f)", multiViewName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z); + doCommand(Doc,"App.activeDocument().%s.Anchor.XDirection = FreeCAD.Vector(%.3f,%.3f,%.3f)", + multiViewName.c_str(), dirs.second.x,dirs.second.y,dirs.second.z); getDocument()->setStatus(App::Document::Status::SkipRecompute, false); } diff --git a/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp b/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp index 481f842d1b..1a0ed2d17d 100644 --- a/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp +++ b/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp @@ -202,7 +202,6 @@ void DrawGuiUtil::dumpPointF(const char* text, const QPointF& p) Base::Console().Message("Point: (%.3f, %.3f)\n",p.x(),p.y()); } - std::pair DrawGuiUtil::get3DDirAndRot() { std::pair result; @@ -228,12 +227,13 @@ std::pair DrawGuiUtil::get3DDirAndRot() SbVec3f upvec = viewer->getUpDirection(); viewDir = Base::Vector3d(dvec[0], dvec[1], dvec[2]); + viewDir = viewDir * (-1.0); // Inventor dir is opposite TD projection dir viewUp = Base::Vector3d(upvec[0],upvec[1],upvec[2]); - Base::Vector3d dirXup = viewDir.Cross(viewUp); //dir X up should give local Right - viewDir = viewDir * (-1.0); // Inventor dir is opposite TD projection dir +// Base::Vector3d dirXup = viewDir.Cross(viewUp); + Base::Vector3d right = viewUp.Cross(viewDir); - result = std::make_pair(viewDir,dirXup); + result = std::make_pair(viewDir,right); return result; } diff --git a/src/Mod/TechDraw/Gui/QGIView.cpp b/src/Mod/TechDraw/Gui/QGIView.cpp index b39ee7f63c..f403949fba 100644 --- a/src/Mod/TechDraw/Gui/QGIView.cpp +++ b/src/Mod/TechDraw/Gui/QGIView.cpp @@ -722,6 +722,7 @@ void QGIView::makeMark(double x, double y, QColor c) vItem->setWidth(2.0); vItem->setRadius(20.0); vItem->setNormalColor(c); + vItem->setFillColor(c); vItem->setPrettyNormal(); vItem->setZValue(ZVALUE::VERTEX); } diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.cpp b/src/Mod/TechDraw/Gui/QGIViewPart.cpp index ba091adbab..23fa425af8 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewPart.cpp @@ -779,13 +779,22 @@ void QGIViewPart::drawSectionLine(TechDraw::DrawViewSection* viewSection, bool b } sectionLine->setDirection(arrowDir.x,arrowDir.y); + //dvp is centered on centroid looking along dvp direction + //dvs is centered on SO looking along section normal + //need to subtract SO from centroid to get displacement Base::Vector3d org = viewSection->SectionOrigin.getValue(); + Base::Vector3d cent = viewPart->getCentroid(); + Base::Vector3d adjOrg = org - cent; double scale = viewPart->getScale(); - Base::Vector3d pOrg = scale * viewPart->projectPoint(org); + + Base::Vector3d pAdjOrg = scale * viewPart->projectPoint(adjOrg); + //now project pOrg onto arrowDir Base::Vector3d displace; - displace.ProjectToLine(pOrg, arrowDir); - Base::Vector3d offset = pOrg + displace; + displace.ProjectToLine(pAdjOrg, arrowDir); + Base::Vector3d offset = pAdjOrg + displace; + +// makeMark(0.0, 0.0); sectionLine->setPos(Rez::guiX(offset.x),Rez::guiX(offset.y)); double sectionSpan; @@ -811,7 +820,6 @@ void QGIViewPart::drawSectionLine(TechDraw::DrawViewSection* viewSection, bool b } else { sectionSpan = height + sectionFudge; } -// sectionSpan = (m_border->rect().height() - m_label->boundingRect().height()) + sectionFudge; xVal = 0.0; yVal = sectionSpan / 2.0; }