Salome HOME
Issue #789: Detach a coincidence from a line object
authorvsv <vitaly.smetannikov@opencascade.com>
Wed, 14 Oct 2015 12:43:04 +0000 (15:43 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Wed, 14 Oct 2015 12:43:25 +0000 (15:43 +0300)
src/PartSet/PartSet_MenuMgr.cpp
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/XGUI/XGUI_ObjectsBrowser.cpp

index 65a2f98d7ed2ad4052e5a98e137559fe2221a204..b4f56d4a82d72233a539bef07751e7c1e24962ea 100644 (file)
@@ -257,49 +257,47 @@ QColor PartSet_MenuMgr::setLineColor(int theId, const QColor theColor, bool theU
 }
 
 
-void PartSet_MenuMgr::onLineDetach(QAction* theAction)
+void addRefCoincidentFeatures(const std::set<AttributePtr>& theRefList, 
+  std::shared_ptr<GeomAPI_Pnt2d>& theRefPnt,
+  QObjectPtrList& theOutList)
 {
-  int aId = theAction->data().toInt();
-  FeaturePtr aLine = myCoinsideLines.at(aId);
-  std::shared_ptr<GeomAPI_Pnt2d> aOrig = PartSet_Tools::getPoint(mySelectedFeature,
-                                                        SketchPlugin_ConstraintCoincidence::ENTITY_A());
-  if (aOrig.get() == NULL)
-    aOrig = PartSet_Tools::getPoint(mySelectedFeature,
-                                    SketchPlugin_ConstraintCoincidence::ENTITY_B());
-  
-  gp_Pnt aOr = aOrig->impl<gp_Pnt>();
-  const std::set<AttributePtr>& aRefsList = aLine->data()->refsToMe();
-
-  QObjectPtrList aToDelFeatures;
   std::set<AttributePtr>::const_iterator aIt;
-  // Find all coincedences corresponded to the selected line in the selected point
-  for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
+  for (aIt = theRefList.cbegin(); aIt != theRefList.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> aPnt = PartSet_Tools::getPoint(aConstrFeature,
-                                            SketchPlugin_ConstraintCoincidence::ENTITY_A());
-      if (aPnt.get() == NULL)
-        aPnt = PartSet_Tools::getPoint(aConstrFeature,
-                                       SketchPlugin_ConstraintCoincidence::ENTITY_B());
+      std::shared_ptr<GeomAPI_Pnt2d> aPnt = PartSet_Tools::getCoincedencePoint(aConstrFeature);
       if (aPnt.get() == NULL)
         return;
       gp_Pnt aP = aPnt->impl<gp_Pnt>();
-      if (aOrig->isEqual(aPnt)) {
-        aToDelFeatures.append(aConstrFeature);
-      } else {
-        aPnt = PartSet_Tools::getPoint(aConstrFeature,
-                                       SketchPlugin_ConstraintCoincidence::ENTITY_B());
-        if (aPnt.get() == NULL)
-          return;
-        aP = aPnt->impl<gp_Pnt>();
-        if (aOrig->isEqual(aPnt)) {
-          aToDelFeatures.append(aConstrFeature);
-          break;
-        }
-      }
+      if (theRefPnt->isEqual(aPnt) && (!theOutList.contains(aConstrFeature))) {
+        theOutList.append(aConstrFeature);
+      } 
     }
   }
+}
+
+void PartSet_MenuMgr::onLineDetach(QAction* theAction)
+{
+  int aId = theAction->data().toInt();
+  FeaturePtr aLine = myCoinsideLines.at(aId);
+  std::shared_ptr<GeomAPI_Pnt2d> aOrig = PartSet_Tools::getCoincedencePoint(mySelectedFeature);
+  if (!aOrig.get())
+    return;
+  
+  const std::set<AttributePtr>& aRefsList = aLine->data()->refsToMe();
+
+  QObjectPtrList aToDelFeatures;
+
+  addRefCoincidentFeatures(aRefsList, aOrig, aToDelFeatures);
+
+  const std::list<ResultPtr>& aResults = aLine->results();
+  std::list<ResultPtr>::const_iterator aResIt;
+  for (aResIt = aResults.cbegin(); aResIt != aResults.cend(); aResIt++) {
+    ResultPtr aResult = (*aResIt);
+    const std::set<AttributePtr>& aRefList = aResult->data()->refsToMe();
+    addRefCoincidentFeatures(aRefList, aOrig, aToDelFeatures);
+  }
   if (aToDelFeatures.size() > 0) {
     XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
     XGUI_Workshop* aWorkshop = aConnector->workshop();
index 8a4c158f3935ca4a311730804b968411d35990c2..57df4e0032216effdd48ec53d3f34061b4a73ba9 100755 (executable)
@@ -15,6 +15,8 @@
 #include <ModelAPI_Session.h>
 #include <ModelAPI_ResultConstruction.h>
 
+#include <SketcherPrs_Tools.h>
+
 #include <XGUI_ModuleConnector.h>
 #include <XGUI_Displayer.h>
 #include <XGUI_Workshop.h>
@@ -676,7 +678,7 @@ void PartSet_Tools::findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>&
   if (!aPnt) return;
   FeaturePtr aObj = ModelAPI_Feature::feature(aPnt->object());
   if (!theList.contains(aObj)) {
-    std::shared_ptr<GeomAPI_Pnt2d> aOrig = getPoint(theStartCoin, theAttr);
+    std::shared_ptr<GeomAPI_Pnt2d> aOrig = getCoincedencePoint(theStartCoin);
     if (aOrig.get() == NULL)
       return;
     theList.append(aObj);
@@ -686,7 +688,7 @@ void PartSet_Tools::findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>&
       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> aPnt = getPoint(aConstrFeature, theAttr);
+        std::shared_ptr<GeomAPI_Pnt2d> aPnt = getCoincedencePoint(aConstrFeature);
         if (aPnt.get() && aOrig->isEqual(aPnt)) {
           findCoincidences(aConstrFeature, theList, SketchPlugin_ConstraintCoincidence::ENTITY_A());
           findCoincidences(aConstrFeature, theList, SketchPlugin_ConstraintCoincidence::ENTITY_B());
@@ -696,6 +698,15 @@ void PartSet_Tools::findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>&
   }
 }
 
+std::shared_ptr<GeomAPI_Pnt2d> PartSet_Tools::getCoincedencePoint(FeaturePtr theStartCoin)
+{
+  std::shared_ptr<GeomAPI_Pnt2d> aPnt = SketcherPrs_Tools::getPoint(theStartCoin.get(), 
+                                                                    SketchPlugin_Constraint::ENTITY_A());
+  if (aPnt.get() == NULL)
+    aPnt = SketcherPrs_Tools::getPoint(theStartCoin.get(), SketchPlugin_Constraint::ENTITY_B());
+  return aPnt;
+}
+
 AttributePtr PartSet_Tools::findAttributeBy2dPoint(ObjectPtr theObj, 
                                                    const TopoDS_Shape theShape, 
                                                    FeaturePtr theSketch)
index f204d3df46997e96e7f81feafa73e2cd4870f90b..438135840c698b4fcb7aac3faefe039fa99d38fd 100755 (executable)
@@ -207,6 +207,12 @@ class PARTSET_EXPORT PartSet_Tools
   */
   static void findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>& theList,
                                std::string theAttr);
+
+  /**
+  * Returns point of a coincedence
+  * \param theStartCoin the coincedence feature
+  */
+  static std::shared_ptr<GeomAPI_Pnt2d> getCoincedencePoint(FeaturePtr theStartCoin);
 };
 
 #endif
index 9eee72dcedd517d3029f5d35186c815e50da7ed0..74d04d9312a80ce65899a35b7495be2607559565 100644 (file)
@@ -176,6 +176,7 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent)
   aLayout->setSpacing(0);
 
   QFrame* aLabelWgt = new QFrame(this);
+  //QWidget* aLabelWgt = new QWidget(this);
   aLabelWgt->setAutoFillBackground(true);
   QPalette aPalet = aLabelWgt->palette();
   aPalet.setColor(QPalette::Window, Qt::white);
@@ -210,6 +211,7 @@ XGUI_ObjectsBrowser::XGUI_ObjectsBrowser(QWidget* theParent)
   aLabelLay->setStretch(1, 1);
 
   myTreeView = new XGUI_DataTree(this);
+  //myTreeView->setFrameShape(QFrame::NoFrame);
   aLayout->addWidget(myTreeView);
 
   aLabelWgt->setFrameShape(myTreeView->frameShape());