]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Make coincidence non selectable
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 8 Apr 2015 12:52:54 +0000 (15:52 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 8 Apr 2015 12:52:54 +0000 (15:52 +0300)
src/PartSet/PartSet_MenuMgr.cpp
src/SketchPlugin/SketchPlugin_Sketch.cpp
src/SketchPlugin/SketchPlugin_Sketch.h
src/SketcherPrs/SketcherPrs_Coincident.cpp

index 9b02aee05ecdbd39b3fba60be968560c08d644b6..7e0442d5157b35de44ef3bd628566f602b177672 100644 (file)
@@ -7,6 +7,7 @@
 #include "PartSet_MenuMgr.h"
 #include "PartSet_Module.h"
 #include "PartSet_SketcherMgr.h"
+#include "PartSet_Tools.h"
 
 #include <GeomAPI_Pnt2d.h>
 #include <GeomDataAPI_Point2D.h>
@@ -15,6 +16,7 @@
 #include <SketchPlugin_Line.h>
 #include <SketchPlugin_Circle.h>
 #include <SketchPlugin_Point.h>
+#include <SketchPlugin_Sketch.h>
 
 #include <ModuleBase_ISelection.h>
 #include <ModuleBase_Operation.h>
@@ -30,6 +32,9 @@
 #include <QAction>
 #include <QMenu>
 
+#include <TopoDS.hxx>
+#include <BRep_Tool.hxx>
+
 PartSet_MenuMgr::PartSet_MenuMgr(PartSet_Module* theModule)
   : QObject(theModule), myModule(theModule), myPrevId(-1)
 {
@@ -117,7 +122,7 @@ void findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>& theList, std::
   if (!theList.contains(aObj)) {
     std::shared_ptr<GeomAPI_Pnt2d> aOrig = getPoint(theStartCoin, theAttr);
     theList.append(aObj);
-    const std::set<AttributePtr> aRefsList = aObj->data()->refsToMe();
+    const std::set<AttributePtr>& aRefsList = aObj->data()->refsToMe();
     std::set<AttributePtr>::const_iterator aIt;
     for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
       std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
@@ -143,43 +148,76 @@ bool PartSet_MenuMgr::addViewerItems(QMenu* theMenu, const QMap<QString, QAction
 
   myCoinsideLines.clear();
   ModuleBase_ISelection* aSelection = myModule->workshop()->selection();
-  QObjectPtrList aObjects = aSelection->selectedPresentations();
-  if (aObjects.size() > 0) {
+
+  NCollection_List<TopoDS_Shape> aShapeList;
+  std::list<ObjectPtr> 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<SketchPlugin_Sketch> aSketch = 
+        std::dynamic_pointer_cast<SketchPlugin_Sketch>(aSketchFea);
+      gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
+      std::shared_ptr<GeomAPI_Pnt> aPnt3d(new GeomAPI_Pnt(aPnt.X(), aPnt.Y(), aPnt.Z()));
+      std::shared_ptr<GeomAPI_Pnt2d> aSelPnt = aSketch->to2D(aPnt3d);
+
+      // Find coincident in these coordinates
+      ObjectPtr aObj = aObjectsList.front();
+      FeaturePtr aFeature = ModelAPI_Feature::feature(aObj);
+      const std::set<AttributePtr>& aRefsList = aFeature->data()->refsToMe();
+      std::set<AttributePtr>::const_iterator aIt;
+      FeaturePtr aCoincident;
+      for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
+        std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
+        FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
+        if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { 
+          std::shared_ptr<GeomAPI_Pnt2d> 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<ObjectPtr>::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)) {
index 377fc0beddf6fc491423951a2417c3ca474e0a2e..64b0c09f6f36f39ddaa0dd51a6c0f9071ec65e01 100644 (file)
 #include <GeomAPI_AISObject.h>
 #include <GeomAPI_Dir.h>
 #include <GeomAPI_PlanarEdges.h>
-#include <GeomAPI_XYZ.h>
 
-#include <GeomDataAPI_Dir.h>
-#include <GeomDataAPI_Point.h>
 #include <GeomAlgoAPI_FaceBuilder.h>
 
 #include <ModelAPI_AttributeRefList.h>
@@ -188,69 +185,6 @@ bool SketchPlugin_Sketch::isSub(ObjectPtr theObject) const
   return false;
 }
 
-std::shared_ptr<GeomAPI_Pnt> SketchPlugin_Sketch::to3D(const double theX, const double theY)
-{
-  std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
-      data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
-  std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-      data()->attribute(SketchPlugin_Sketch::NORM_ID()));
-  std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-      data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
-  std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
-
-  std::shared_ptr<GeomAPI_XYZ> aSum = aC->pnt()->xyz()->added(aX->dir()->xyz()->multiplied(theX))
-      ->added(aY->xyz()->multiplied(theY));
-
-  return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum));
-}
-
-std::shared_ptr<GeomAPI_Pnt2d> SketchPlugin_Sketch::to2D(
-  const std::shared_ptr<GeomAPI_Pnt>& thePnt)
-{
-  std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
-      data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
-  std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-      data()->attribute(SketchPlugin_Sketch::NORM_ID()));
-  std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-      data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
-  std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
-  return thePnt->to2D(aC->pnt(), aX->dir(), aY);
-}
-
-
-bool SketchPlugin_Sketch::isPlaneSet()
-{
-  std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-      data()->attribute(SketchPlugin_Sketch::NORM_ID()));
-
-  return aNormal && !(aNormal->x() == 0 && aNormal->y() == 0 && aNormal->z() == 0);
-}
-
-std::shared_ptr<GeomAPI_Pln> SketchPlugin_Sketch::plane()
-{
-  std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
-      data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
-  std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-      data()->attribute(SketchPlugin_Sketch::NORM_ID()));
-
-  if (!anOrigin || !aNorm)
-    return std::shared_ptr<GeomAPI_Pln>();
-
-  return std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(anOrigin->pnt(), aNorm->dir()));
-}
-
-std::shared_ptr<GeomAPI_Ax3> SketchPlugin_Sketch::coordinatePlane() const
-{
-  DataPtr aData = data();
-  std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
-    aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
-  std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-    aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
-  std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-    aData->attribute(SketchPlugin_Sketch::NORM_ID()));
-
-  return std::shared_ptr<GeomAPI_Ax3>(new GeomAPI_Ax3(aC->pnt(), aX->dir(), aNorm->dir()));
-}
 
 void SketchPlugin_Sketch::erase()
 {
index 0c88f0d8f097c59f2dff814f9344ac942f343de9..d7e65d5486ff8bcc8bbf6a0b08c4573e2c0e79ed 100644 (file)
@@ -13,6 +13,9 @@
 #include <GeomAPI_Pln.h>
 #include <GeomAPI_IPresentable.h>
 #include <GeomAPI_Ax3.h>
+#include <GeomAPI_XYZ.h>
+#include <GeomDataAPI_Point.h>
+#include <GeomDataAPI_Dir.h>
 #include <list>
 
 #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<GeomAPI_Pnt> to3D(const double theX, const double theY);
+  /// \param theX an X coordinate
+  /// \param theY an Y coordinate
+  std::shared_ptr<GeomAPI_Pnt> to3D(const double theX, const double theY) const
+  {
+    std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+        data()->attribute(ORIGIN_ID()));
+    std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+        data()->attribute(NORM_ID()));
+    std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+        data()->attribute(DIRX_ID()));
+    std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
+
+    std::shared_ptr<GeomAPI_XYZ> aSum = aC->pnt()->xyz()->added(aX->dir()->xyz()->multiplied(theX))
+        ->added(aY->xyz()->multiplied(theY));
+
+    return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aSum));
+  }
+  
+  /// Returns the point projected into the sketch plane
+  /// \param thePnt a source 3d point
+  std::shared_ptr<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& thePnt) const
+  {
+    std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+        data()->attribute(ORIGIN_ID()));
+    std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+        data()->attribute(NORM_ID()));
+    std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+        data()->attribute(DIRX_ID()));
+    std::shared_ptr<GeomAPI_Dir> 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<GeomAPI_Pln> plane();
+  std::shared_ptr<GeomAPI_Pln> plane() const
+  {
+    std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+        data()->attribute(ORIGIN_ID()));
+    std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+        data()->attribute(NORM_ID()));
 
-  SKETCHPLUGIN_EXPORT std::shared_ptr<GeomAPI_Ax3> coordinatePlane() const;
+    if (!anOrigin || !aNorm)
+      return std::shared_ptr<GeomAPI_Pln>();
+
+    return std::shared_ptr<GeomAPI_Pln>(new GeomAPI_Pln(anOrigin->pnt(), aNorm->dir()));
+  }
+
+  /// Returns currently defined plane as an object of Ax3
+  std::shared_ptr<GeomAPI_Ax3> coordinatePlane() const
+  {
+    DataPtr aData = data();
+    std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+      aData->attribute(ORIGIN_ID()));
+    std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+      aData->attribute(DIRX_ID()));
+    std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+      aData->attribute(NORM_ID()));
+
+    return std::shared_ptr<GeomAPI_Ax3>(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<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+        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<GeomAPI_Pnt2d> to2D(const std::shared_ptr<GeomAPI_Pnt>& 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
index 3520df99884db5881a6d22137b95cf51e6b08dca..b85d018b361da4502cfa8bbbc51b465261de0799 100644 (file)
@@ -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)