]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2927: Show/Hide markers on free points
authorvsv <vsv@opencascade.com>
Wed, 19 Jun 2019 14:50:38 +0000 (17:50 +0300)
committervsv <vsv@opencascade.com>
Wed, 19 Jun 2019 14:50:38 +0000 (17:50 +0300)
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_SketcherMgr.cpp
src/PartSet/PartSet_SketcherMgr.h
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/PartSet/PartSet_WidgetSketchLabel.h

index f202db9f6c6a8e2ea18d4eb7534f43ded9d4ad95..bbf82b6be2110c219c9afeb8ffc1fa1611278f50 100644 (file)
@@ -892,6 +892,8 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th
       mySketchMgr, SLOT(onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>&)));
     connect(aLabelWgt, SIGNAL(showConstraintToggled(int, bool)),
       mySketchMgr, SLOT(onShowConstraintsToggle(int, bool)));
+    connect(aLabelWgt, SIGNAL(showFreePoints(bool)), mySketchMgr, SLOT(onShowPoints(bool)));
+    aLabelWgt->setShowPointsState(mySketchMgr->isShowFreePointsShown());
     aWgt = aLabelWgt;
   } else if (theType == "sketch-2dpoint_selector") {
     PartSet_WidgetPoint2D* aPointWgt = new PartSet_WidgetPoint2D(theParent, aWorkshop,
index cca6529d8668a2ea5e9c1d70973c83aa58343685..40925340bfeae306f3c609731460c9ad00e19e61 100644 (file)
@@ -61,6 +61,8 @@
 
 #include <GeomDataAPI_Point2D.h>
 
+#include <GeomAPI_Shape.h>
+
 #include <Events_Loop.h>
 
 #include <SketchPlugin_Line.h>
@@ -1065,6 +1067,7 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
     delete myExternalPointsMgr;
     myExternalPointsMgr = 0;
   }
+  onShowPoints(false);
 
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
 
@@ -1163,6 +1166,8 @@ void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
   }
   if (isClearSelectionPossible)
     workshop()->selector()->clearSelection();
+  if (myPointsHighlight.size())
+    onShowPoints(true);
 }
 
 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
@@ -1990,3 +1995,63 @@ XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
   return workshop()->operationMgr();
 }
 
+void PartSet_SketcherMgr::onShowPoints(bool toShow)
+{
+  if (!myCurrentSketch.get())
+    return;
+  ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
+  ModuleBase_IViewer* aViewer = aWorkshop->viewer();
+  Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
+
+  bool aToUpdate = false;
+  if (toShow) {
+    std::list<ResultPtr> aFreePoints = SketcherPrs_Tools::getFreePoints(myCurrentSketch);
+
+    // Delete obsolete presentations
+    std::list<ResultPtr> aDelList;
+    foreach(ResultPtr aObj, myPointsHighlight.keys()) {
+      bool aFound = (std::find(aFreePoints.begin(), aFreePoints.end(), aObj) != aFreePoints.end());
+      if (!aFound)
+        aDelList.push_back(aObj);
+    }
+    foreach(ResultPtr aObj, aDelList) {
+      aContext->Remove(myPointsHighlight[aObj], false);
+      aToUpdate = true;
+      myPointsHighlight.remove(aObj);
+    }
+
+    // Display new objects
+    QList<ResultPtr> aKeysList = myPointsHighlight.keys();
+    std::list<ResultPtr>::const_iterator aIt;
+    for (aIt = aFreePoints.cbegin(); aIt != aFreePoints.cend(); aIt++) {
+      if (!aKeysList.contains(*aIt)) {
+        GeomShapePtr aShapePtr = (*aIt)->shape();
+        TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
+        Handle(AIS_Shape) aShapePrs = new AIS_Shape(aShape);
+        aShapePrs->SetColor(Quantity_NOC_BLUE1);
+        aShapePrs->SetZLayer(Graphic3d_ZLayerId_Top);
+        Handle(Prs3d_Drawer) aDrawer = aShapePrs->Attributes();
+        if (aDrawer->HasOwnPointAspect()) {
+          aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_O_STAR);
+          aDrawer->PointAspect()->SetColor(Quantity_NOC_BLUE1);
+          aDrawer->PointAspect()->SetScale(2);
+        }
+        else
+          aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_O_STAR, Quantity_NOC_BLUE1, 2));
+        aContext->Display(aShapePrs, false);
+        aContext->Deactivate(aShapePrs);
+        myPointsHighlight[*aIt] = aShapePrs;
+        aToUpdate = true;
+      }
+    }
+  }
+  else {
+    foreach(Handle(AIS_Shape) aPrs, myPointsHighlight.values()) {
+      aContext->Remove(aPrs, false);
+      aToUpdate = true;
+    }
+    myPointsHighlight.clear();
+  }
+  if (aToUpdate)
+    aViewer->update();
+}
index 0be54180b28ed7bb14e9dc9d9de0358af71d45ac..07c3160e6b226cdee4c875af93cdc460881f359c 100644 (file)
@@ -41,6 +41,7 @@
 
 #include <TopoDS_Shape.hxx>
 #include <TopTools_MapOfShape.hxx>
+#include <AIS_Shape.hxx>
 
 #include <QObject>
 #include <QList>
@@ -335,10 +336,16 @@ public:
   void updateBySketchParameters(const PartSet_Tools::ConstraintVisibleState& theType,
                                 bool theState);
 
+  bool isShowFreePointsShown() const {
+    return myPointsHighlight.size() > 0;
+  }
+
 public slots:
   /// Process sketch plane selected event
   void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
 
+  void onShowPoints(bool toShow);
+
 private slots:
   /// Toggle show constraints
   void onShowConstraintsToggle(int theType, bool theState);
@@ -452,6 +459,8 @@ private:
   QMap<PartSet_Tools::ConstraintVisibleState, bool> myIsConstraintsShown;
 
   PartSet_ExternalPointsMgr* myExternalPointsMgr;
+
+  QMap<ResultPtr, Handle(AIS_Shape)> myPointsHighlight;
 };
 
 
index aea6f47f19d9ad689588426ad181a424111f6f96..75386d957bd54a5a131d59174df550e0d054546c 100644 (file)
@@ -167,7 +167,9 @@ myIsSelection(false)
     if (toShowConstraints.contains(aState))
       aShowConstraints->setChecked(toShowConstraints[aState]);
   }
-
+  myShowPoints = new QCheckBox(tr("Show free points"), this);
+  connect(myShowPoints, SIGNAL(toggled(bool)), this, SIGNAL(showFreePoints(bool)));
+  aLayout->addWidget(myShowPoints);
 
   QPushButton* aPlaneBtn = new QPushButton(tr("Change sketch plane"), aSecondWgt);
   connect(aPlaneBtn, SIGNAL(clicked(bool)), SLOT(onChangePlane()));
@@ -698,4 +700,11 @@ void PartSet_WidgetSketchLabel::onChangePlane()
     aMgr->startOperation();
     myOpenTransaction = true;
   }
-}
\ No newline at end of file
+}
+
+void PartSet_WidgetSketchLabel::setShowPointsState(bool theState)
+{
+  bool aBlock = myShowPoints->blockSignals(true);
+  myShowPoints->setChecked(theState);
+  myShowPoints->blockSignals(aBlock);
+}
index 4add82b00b9dae8e791c76e8f92e16956d01ee28..74a16f2248f33199e47f8d54c402636130499e05 100644 (file)
@@ -101,6 +101,10 @@ public:
   virtual void setHighlighted(bool) { /*do nothing*/ };
   virtual void enableFocusProcessing();
 
+  /// Set current state of show free points
+  /// \param theState a state of the corresponded check box
+  void setShowPointsState(bool theState);
+
   /// Returns True if the selected presentation can be used for plane definition
   /// \param thePrs a presentation
   static bool canFillSketch(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
@@ -114,6 +118,8 @@ signals:
   /// \param theState a state of the check box
   void showConstraintToggled(int theType, bool theState);
 
+  void showFreePoints(bool toShow);
+
 protected:
   /// Creates a backup of the current values of the attribute
   /// It should be realized in the specific widget because of different
@@ -216,6 +222,7 @@ private:
 
   QCheckBox* myViewInverted;
   QCheckBox* myRemoveExternal;
+  QCheckBox* myShowPoints;
 
   QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*> myShowConstraints;