From 7d875ca16795ee11d858f0c7461a5063d7481720 Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 8 Apr 2015 15:52:54 +0300 Subject: [PATCH] Make coincidence non selectable --- src/PartSet/PartSet_MenuMgr.cpp | 98 +++++++++++++++------- src/SketchPlugin/SketchPlugin_Sketch.cpp | 66 --------------- src/SketchPlugin/SketchPlugin_Sketch.h | 80 +++++++++++++++--- src/SketcherPrs/SketcherPrs_Coincident.cpp | 10 +-- 4 files changed, 142 insertions(+), 112 deletions(-) diff --git a/src/PartSet/PartSet_MenuMgr.cpp b/src/PartSet/PartSet_MenuMgr.cpp index 9b02aee05..7e0442d51 100644 --- a/src/PartSet/PartSet_MenuMgr.cpp +++ b/src/PartSet/PartSet_MenuMgr.cpp @@ -7,6 +7,7 @@ #include "PartSet_MenuMgr.h" #include "PartSet_Module.h" #include "PartSet_SketcherMgr.h" +#include "PartSet_Tools.h" #include #include @@ -15,6 +16,7 @@ #include #include #include +#include #include #include @@ -30,6 +32,9 @@ #include #include +#include +#include + PartSet_MenuMgr::PartSet_MenuMgr(PartSet_Module* theModule) : QObject(theModule), myModule(theModule), myPrevId(-1) { @@ -117,7 +122,7 @@ void findCoincidences(FeaturePtr theStartCoin, QList& theList, std:: if (!theList.contains(aObj)) { std::shared_ptr aOrig = getPoint(theStartCoin, theAttr); theList.append(aObj); - const std::set aRefsList = aObj->data()->refsToMe(); + const std::set& aRefsList = aObj->data()->refsToMe(); std::set::const_iterator aIt; for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) { std::shared_ptr aAttr = (*aIt); @@ -143,43 +148,76 @@ bool PartSet_MenuMgr::addViewerItems(QMenu* theMenu, const QMapworkshop()->selection(); - QObjectPtrList aObjects = aSelection->selectedPresentations(); - if (aObjects.size() > 0) { + + NCollection_List aShapeList; + std::list aObjectsList; + aSelection->selectedShapes(aShapeList, aObjectsList); + bool aIsDetach = false; + + if (aShapeList.Extent() == 1) { + TopoDS_Shape aShape = aShapeList.First(); + if (aShape.ShapeType() == TopAbs_VERTEX) { + // Find 2d coordinates + FeaturePtr aSketchFea = myModule->sketchMgr()->activeSketch(); + std::shared_ptr aSketch = + std::dynamic_pointer_cast(aSketchFea); + gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape)); + std::shared_ptr aPnt3d(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z())); + std::shared_ptr aSelPnt = aSketch->to2D(aPnt3d); + + // Find coincident in these coordinates + ObjectPtr aObj = aObjectsList.front(); + FeaturePtr aFeature = ModelAPI_Feature::feature(aObj); + const std::set& aRefsList = aFeature->data()->refsToMe(); + std::set::const_iterator aIt; + FeaturePtr aCoincident; + for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) { + std::shared_ptr aAttr = (*aIt); + FeaturePtr aConstrFeature = std::dynamic_pointer_cast(aAttr->owner()); + if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { + std::shared_ptr a2dPnt = getPoint(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A()); + if (aSelPnt->isEqual(a2dPnt)) { + aCoincident = aConstrFeature; + break; + } + } + } + // If we have coincidence then add Detach menu + if (aCoincident.get() != NULL) { + mySelectedFeature = aCoincident; + findCoincidences(mySelectedFeature, myCoinsideLines, SketchPlugin_ConstraintCoincidence::ENTITY_A()); + findCoincidences(mySelectedFeature, myCoinsideLines, SketchPlugin_ConstraintCoincidence::ENTITY_B()); + if (myCoinsideLines.size() > 0) { + aIsDetach = true; + QMenu* aSubMenu = theMenu->addMenu(tr("Detach")); + QAction* aAction; + int i = 0; + foreach (FeaturePtr aCoins, myCoinsideLines) { + aAction = aSubMenu->addAction(aCoins->data()->name().c_str()); + aAction->setData(QVariant(i)); + i++; + } + connect(aSubMenu, SIGNAL(hovered(QAction*)), SLOT(onLineHighlighted(QAction*))); + connect(aSubMenu, SIGNAL(aboutToHide()), SLOT(onDetachMenuHide())); + connect(aSubMenu, SIGNAL(triggered(QAction*)), SLOT(onLineDetach(QAction*))); + } + } + } + } + if ((!aIsDetach) && (aObjectsList.size() > 0)) { bool hasFeature = false; FeaturePtr aFeature; - foreach(ObjectPtr aObject, aObjects) { + std::list::const_iterator aIt; + ObjectPtr aObject; + for (aIt = aObjectsList.cbegin(); aIt != aObjectsList.cend(); ++aIt) { + aObject = (*aIt); aFeature = ModelAPI_Feature::feature(aObject); if (aFeature.get() != NULL) { hasFeature = true; } } - if (hasFeature) { - bool aIsDetach = false; - if (aObjects.size() == 1) { - if (aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { - /// If the feature is coincident then we use Detach command instead Delete - mySelectedFeature = aFeature; - findCoincidences(mySelectedFeature, myCoinsideLines, SketchPlugin_ConstraintCoincidence::ENTITY_A()); - findCoincidences(mySelectedFeature, myCoinsideLines, SketchPlugin_ConstraintCoincidence::ENTITY_B()); - if (myCoinsideLines.size() > 0) { - aIsDetach = true; - QMenu* aSubMenu = theMenu->addMenu(tr("Detach")); - QAction* aAction; - int i = 0; - foreach (FeaturePtr aCoins, myCoinsideLines) { - aAction = aSubMenu->addAction(aCoins->data()->name().c_str()); - aAction->setData(QVariant(i)); - i++; - } - connect(aSubMenu, SIGNAL(hovered(QAction*)), SLOT(onLineHighlighted(QAction*))); - connect(aSubMenu, SIGNAL(aboutToHide()), SLOT(onDetachMenuHide())); - connect(aSubMenu, SIGNAL(triggered(QAction*)), SLOT(onLineDetach(QAction*))); - } - } - } - if (!aIsDetach) + if (hasFeature) theMenu->addAction(theStdActions["DELETE_CMD"]); - } } bool isAuxiliary; if (canSetAuxiliary(isAuxiliary)) { diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 377fc0bed..64b0c09f6 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -12,10 +12,7 @@ #include #include #include -#include -#include -#include #include #include @@ -188,69 +185,6 @@ bool SketchPlugin_Sketch::isSub(ObjectPtr theObject) const return false; } -std::shared_ptr SketchPlugin_Sketch::to3D(const double theX, const double theY) -{ - std::shared_ptr aC = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Sketch::ORIGIN_ID())); - std::shared_ptr aNorm = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Sketch::NORM_ID())); - std::shared_ptr aX = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Sketch::DIRX_ID())); - std::shared_ptr aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir()))); - - std::shared_ptr aSum = aC->pnt()->xyz()->added(aX->dir()->xyz()->multiplied(theX)) - ->added(aY->xyz()->multiplied(theY)); - - return std::shared_ptr(new GeomAPI_Pnt(aSum)); -} - -std::shared_ptr SketchPlugin_Sketch::to2D( - const std::shared_ptr& thePnt) -{ - std::shared_ptr aC = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Sketch::ORIGIN_ID())); - std::shared_ptr aNorm = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Sketch::NORM_ID())); - std::shared_ptr aX = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Sketch::DIRX_ID())); - std::shared_ptr aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir()))); - return thePnt->to2D(aC->pnt(), aX->dir(), aY); -} - - -bool SketchPlugin_Sketch::isPlaneSet() -{ - std::shared_ptr aNormal = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Sketch::NORM_ID())); - - return aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0); -} - -std::shared_ptr SketchPlugin_Sketch::plane() -{ - std::shared_ptr anOrigin = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Sketch::ORIGIN_ID())); - std::shared_ptr aNorm = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Sketch::NORM_ID())); - - if (!anOrigin || !aNorm) - return std::shared_ptr(); - - return std::shared_ptr(new GeomAPI_Pln(anOrigin->pnt(), aNorm->dir())); -} - -std::shared_ptr SketchPlugin_Sketch::coordinatePlane() const -{ - DataPtr aData = data(); - std::shared_ptr aC = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Sketch::ORIGIN_ID())); - std::shared_ptr aX = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Sketch::DIRX_ID())); - std::shared_ptr aNorm = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Sketch::NORM_ID())); - - return std::shared_ptr(new GeomAPI_Ax3(aC->pnt(), aX->dir(), aNorm->dir())); -} void SketchPlugin_Sketch::erase() { diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index 0c88f0d8f..d7e65d548 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -13,6 +13,9 @@ #include #include #include +#include +#include +#include #include #define YZ_PLANE_COLOR "#ff0000" @@ -85,7 +88,37 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature//, public GeomAPI_I } /// Converts a 2D sketch space point into point in 3D space - SKETCHPLUGIN_EXPORT std::shared_ptr to3D(const double theX, const double theY); + /// \param theX an X coordinate + /// \param theY an Y coordinate + std::shared_ptr to3D(const double theX, const double theY) const + { + std::shared_ptr aC = std::dynamic_pointer_cast( + data()->attribute(ORIGIN_ID())); + std::shared_ptr aNorm = std::dynamic_pointer_cast( + data()->attribute(NORM_ID())); + std::shared_ptr aX = std::dynamic_pointer_cast( + data()->attribute(DIRX_ID())); + std::shared_ptr aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir()))); + + std::shared_ptr aSum = aC->pnt()->xyz()->added(aX->dir()->xyz()->multiplied(theX)) + ->added(aY->xyz()->multiplied(theY)); + + return std::shared_ptr(new GeomAPI_Pnt(aSum)); + } + + /// Returns the point projected into the sketch plane + /// \param thePnt a source 3d point + std::shared_ptr to2D(const std::shared_ptr& thePnt) const + { + std::shared_ptr aC = std::dynamic_pointer_cast( + data()->attribute(ORIGIN_ID())); + std::shared_ptr aNorm = std::dynamic_pointer_cast( + data()->attribute(NORM_ID())); + std::shared_ptr aX = std::dynamic_pointer_cast( + data()->attribute(DIRX_ID())); + std::shared_ptr aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir()))); + return thePnt->to2D(aC->pnt(), aX->dir(), aY); + } /// Returns true if this feature must be displayed in the history (top level of Part tree) SKETCHPLUGIN_EXPORT virtual bool isInHistory() @@ -97,11 +130,43 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature//, public GeomAPI_I SketchPlugin_Sketch(); /// Returns the basis plane for the sketch - std::shared_ptr plane(); + std::shared_ptr plane() const + { + std::shared_ptr anOrigin = std::dynamic_pointer_cast( + data()->attribute(ORIGIN_ID())); + std::shared_ptr aNorm = std::dynamic_pointer_cast( + data()->attribute(NORM_ID())); - SKETCHPLUGIN_EXPORT std::shared_ptr coordinatePlane() const; + if (!anOrigin || !aNorm) + return std::shared_ptr(); + + return std::shared_ptr(new GeomAPI_Pln(anOrigin->pnt(), aNorm->dir())); + } + + /// Returns currently defined plane as an object of Ax3 + std::shared_ptr coordinatePlane() const + { + DataPtr aData = data(); + std::shared_ptr aC = std::dynamic_pointer_cast( + aData->attribute(ORIGIN_ID())); + std::shared_ptr aX = std::dynamic_pointer_cast( + aData->attribute(DIRX_ID())); + std::shared_ptr aNorm = std::dynamic_pointer_cast( + aData->attribute(NORM_ID())); + + return std::shared_ptr(new GeomAPI_Ax3(aC->pnt(), aX->dir(), aNorm->dir())); + } + + /// Checks whether the plane is set in the sketch. + /// \returns the boolean state + bool isPlaneSet() const + { + std::shared_ptr aNormal = std::dynamic_pointer_cast( + data()->attribute(NORM_ID())); + + return aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0); + } - //virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious); /// removes also all sub-sketch elements SKETCHPLUGIN_EXPORT virtual void erase(); @@ -128,14 +193,7 @@ class SketchPlugin_Sketch : public ModelAPI_CompositeFeature//, public GeomAPI_I /// Construction result is allways recomuted on the fly SKETCHPLUGIN_EXPORT virtual bool isPersistentResult() {return false;} - /// Returns the point projected into the sketch plane - std::shared_ptr to2D(const std::shared_ptr& thePnt); - SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); -protected: - /// Checks whether the plane is set in the sketch. - /// \returns the boolean state - bool isPlaneSet(); }; #endif diff --git a/src/SketcherPrs/SketcherPrs_Coincident.cpp b/src/SketcherPrs/SketcherPrs_Coincident.cpp index 3520df998..b85d018b3 100644 --- a/src/SketcherPrs/SketcherPrs_Coincident.cpp +++ b/src/SketcherPrs/SketcherPrs_Coincident.cpp @@ -70,11 +70,11 @@ void SketcherPrs_Coincident::Compute(const Handle(PrsMgr_PresentationManager3d)& void SketcherPrs_Coincident::ComputeSelection(const Handle(SelectMgr_Selection)& aSelection, const Standard_Integer aMode) { - if ((aMode == 0) || (aMode == SketcherPrs_Tools::Sel_Constraint)) { - Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this, 10); - Handle(Select3D_SensitivePoint) aSp = new Select3D_SensitivePoint(aOwn, myPoint); - aSelection->Add(aSp); - } +// if ((aMode == 0) || (aMode == SketcherPrs_Tools::Sel_Constraint)) { +// Handle(SelectMgr_EntityOwner) aOwn = new SelectMgr_EntityOwner(this, 10); +// Handle(Select3D_SensitivePoint) aSp = new Select3D_SensitivePoint(aOwn, myPoint); +// aSelection->Add(aSp); +// } } void SketcherPrs_Coincident::SetColor(const Quantity_NameOfColor aCol) -- 2.39.2