]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Task #2997: Show objects with DoF
authorvsv <vsv@opencascade.com>
Tue, 8 Oct 2019 15:41:57 +0000 (18:41 +0300)
committervsv <vsv@opencascade.com>
Tue, 8 Oct 2019 15:41:57 +0000 (18:41 +0300)
src/ModelAPI/ModelAPI_Events.h
src/PartSet/PartSet_SketcherMgr.cpp
src/PartSet/PartSet_SketcherMgr.h
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h
src/SketchSolver/SketchSolver_Group.cpp
src/SketchSolver/SketchSolver_Group.h
src/SketchSolver/SketchSolver_Manager.cpp
src/SketchSolver/SketchSolver_Storage.h

index 042c06a41d040c82902eb7c1d3bfda56037e454f..f424d421437025642b8766c8f37e16085effc3c5 100644 (file)
@@ -101,6 +101,12 @@ static const char * EVENT_STABILITY_CHANGED = "StabilityChanged";
 /// Event ID that the sketch is prepared and all grouped messages for the solver may be flushed
 static const char * EVENT_SKETCH_PREPARED = "SketchPrepared";
 
+/// Event ID that provides a request for list of non-fixed objects necessary for DoF = 0
+static const char * EVENT_GET_DOF_OBJECTS = "GetDoFObjects";
+
+/// Event ID that provides a request for list of non-fixed objects necessary for DoF = 0
+static const char * EVENT_DOF_OBJECTS = "DoFObjects";
+
 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
 class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
 {
index 1c88fc4f6bf76b4f5e81138a30fd2c795abdae34..aa639e247c9195493ef4968db6d95f3c5c5896ac 100644 (file)
 #include <QMessageBox>
 #include <QMainWindow>
 
+#include <set>
+
 //#define DEBUG_DO_NOT_BY_ENTER
 //#define DEBUG_SKETCHER_ENTITIES
 //#define DEBUG_SKETCH_ENTITIES_ON_MOVE
@@ -201,6 +203,8 @@ PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
 
   registerSelectionFilter(SF_SketchCirclePointFilter, new PartSet_CirclePointFilter(anIWorkshop));
   registerSelectionFilter(SF_SketchPlaneFilter, new ModuleBase_ShapeInPlaneFilter());
+
+  Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_DOF_OBJECTS));
 }
 
 PartSet_SketcherMgr::~PartSet_SketcherMgr()
@@ -2113,6 +2117,30 @@ void PartSet_SketcherMgr::onShowPoints(bool toShow)
     aViewer->update();
 }
 
+void PartSet_SketcherMgr::processEvent(const std::shared_ptr<Events_Message>& theMessage)
+{
+  if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOF_OBJECTS)) {
+    std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
+      std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
+    std::set<ObjectPtr> aObjects = anUpdateMsg->objects();
+    std::set<ObjectPtr>::const_iterator aIt;
+    QList<ModuleBase_ViewerPrsPtr> aPrsList;
+    for (aIt = aObjects.cbegin(); aIt != aObjects.cend(); aIt++) {
+      FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*aIt);
+      if (aFeature.get()) {
+        std::list<ResultPtr> aRes = aFeature->results();
+        std::list<ResultPtr>::const_iterator aIt;
+        for (aIt = aRes.cbegin(); aIt != aRes.cend(); ++aIt) {
+          ModuleBase_ViewerPrsPtr aPrsPtr(new ModuleBase_ViewerPrs(*aIt));
+          aPrsList.append(aPrsPtr);
+        }
+      }
+    }
+    if (aPrsList.size() > 0) {
+      myModule->workshop()->setSelected(aPrsList);
+    }
+  }
+}
 
 void PartSet_Fitter::fitAll(Handle(V3d_View) theView)
 {
index 7259514a4eb54083d520cf7e8863bc929d96a348..24e6347d16d58c37908fb6c4d48880c46f73dc86 100644 (file)
@@ -29,6 +29,7 @@
 #include <ModelAPI_Attribute.h>
 #include <ModelAPI_CompositeFeature.h>
 #include <ModelAPI_Result.h>
+#include <Events_Listener.h>
 #include <ModuleBase_SelectionFilterType.h>
 
 #include <ModuleBase_Definitions.h>
@@ -97,7 +98,7 @@ private:
   displayed in the viewer. After the sketch create/edit operation is finished, the sub-feature
   are hidden, the sketch feature result is displayed
 */
-class PARTSET_EXPORT PartSet_SketcherMgr : public QObject
+class PARTSET_EXPORT PartSet_SketcherMgr : public QObject, public Events_Listener
 {
   Q_OBJECT
   /// Struct to define gp point, with the state is the point is initialized
@@ -371,6 +372,11 @@ public:
 
   PartSet_Module* module() const { return myModule; }
 
+  /** \brief Implementation of Event Listener method
+  *  \param[in] theMessage the data of the event
+  */
+  virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
+
 public slots:
   /// Process sketch plane selected event
   void onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePln);
index 2d9fd7d4f353dd8950e077b82cf62b1f87f10c0d..1f969d0ebd6ccb0ae0ba447d60fe17ea7d4d2353 100644 (file)
@@ -38,6 +38,7 @@
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_Tools.h>
 #include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Events.h>
 
 #include <ModuleBase_Operation.h>
 #include <ModuleBase_ViewerPrs.h>
@@ -761,7 +762,9 @@ bool PartSet_WidgetSketchLabel::restoreValueCustom()
           myShowDOFBtn->hide();
         } else {
           myDoFLabel->setText(tr("DoF (degrees of freedom) = ") + aVal);
-          myShowDOFBtn->show();
+          CompositeFeaturePtr aCompFeature = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
+          if (aCompFeature.get() && aCompFeature->numberOfSubs() > 1)
+            myShowDOFBtn->show();
         }
       }
     }
@@ -776,5 +779,10 @@ bool PartSet_WidgetSketchLabel::restoreValueCustom()
 
 void PartSet_WidgetSketchLabel::onShowDOF()
 {
-
-}
\ No newline at end of file
+  CompositeFeaturePtr aCompFeature = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
+  if (aCompFeature.get() && aCompFeature->numberOfSubs() > 1) {
+    static const Events_ID anEvent = Events_Loop::eventByName(EVENT_GET_DOF_OBJECTS);
+    ModelAPI_EventCreator::get()->sendUpdated(aCompFeature->subFeature(0), anEvent);
+    Events_Loop::loop()->flush(anEvent);
+  }
+}
index 6404c4636515e8f72ca99d5532dc012a810d690f..eb3542bdd0f20b2d8ddb9ebeed93dccb4fd7ec60 100644 (file)
@@ -656,7 +656,7 @@ PlaneGCSSolver_Solver::SolveStatus PlaneGCSSolver_Storage::checkDegeneratedGeome
 }
 
 
-void PlaneGCSSolver_Storage::getUnderconstrainedGeometry(std::set<FeaturePtr>& theFeatures) const
+void PlaneGCSSolver_Storage::getUnderconstrainedGeometry(std::set<ObjectPtr>& theFeatures) const
 {
   std::vector<double*> aFreeParams;
   mySketchSolver->getFreeParameters(aFreeParams);
index 3c350e90dd0eb3a8fdca1c0e3685cdb5e46efee8..8d452a85749a10032aa4098f74b26b0ce91fe9e7 100644 (file)
@@ -96,7 +96,7 @@ public:
   virtual void adjustParametrizationOfArcs();
 
   /// \brief Return list of features which are not fully constrained
-  virtual void getUnderconstrainedGeometry(std::set<FeaturePtr>& theFeatures) const;
+  virtual void getUnderconstrainedGeometry(std::set<ObjectPtr>& theFeatures) const;
 
 private:
   /// \brief Convert feature using specified builder.
index 2662f564de0453be83fbed8d288390117bf776cd..96c0a29687a66e1008520dd4d398e5244df9ce18 100644 (file)
@@ -497,7 +497,7 @@ bool SketchSolver_Group::areConstraintsValid() const
   return true;
 }
 
-void SketchSolver_Group::underconstrainedFeatures(std::set<FeaturePtr>& theFeatures) const
+void SketchSolver_Group::underconstrainedFeatures(std::set<ObjectPtr>& theFeatures) const
 {
   myStorage->getUnderconstrainedGeometry(theFeatures);
 }
index e76edf2d23e24eb1c02e3305b40da63da3fcd0a6..45407ddb8f47884f6dbc4efb5a4ede2d0a567a25 100644 (file)
@@ -116,7 +116,7 @@ class SketchSolver_Group
   bool resolveConstraints();
 
   /// \brief Find the list of features, which are not fully constrained.
-  void underconstrainedFeatures(std::set<FeaturePtr>& theFeatures) const;
+  void underconstrainedFeatures(std::set<ObjectPtr>& theFeatures) const;
 
   /// \brief Block or unblock events sent by features in this group
   void blockEvents(bool isBlocked);
index 04fc5914875e1c64474d55d658a489ad137b1e75..6f000ec6c8d91a46d443836ae7d4a8a231172ee9 100644 (file)
@@ -114,6 +114,7 @@ SketchSolver_Manager::SketchSolver_Manager()
   ////Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_SOLVER_FAILED));
   ////Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_SOLVER_REPAIRED));
   Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_SKETCH_PREPARED));
+  Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_GET_DOF_OBJECTS));
 }
 
 SketchSolver_Manager::~SketchSolver_Manager()
@@ -223,19 +224,35 @@ void SketchSolver_Manager::processEvent(
     }
     myIsComputed = false;
   }
-////  else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_FEATURES_OF_FREEDOM)) {
-////    FeaturePtr aComposite = theMessage->sketch();
-////    std::shared_ptr<SketchPlugin_Feature> aSketch =
-////        std::dynamic_pointer_cast<SketchPlugin_Feature>(aComposite);
-////    if (aSketch) {
-////      SketchGroupPtr aGroup = findGroup(aSketch);
-////
-////      std::set<FeaturePtr> aFreeFeatures;
-////      aGroup->underconstrainedFeatures(aFreeFeatures);
-////
-////      // TODO: send features to GUI
-////    }
-////  }
+  else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_GET_DOF_OBJECTS)) {
+    std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
+      std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
+    std::set<ObjectPtr> aObjects = anUpdateMsg->objects();
+    if (aObjects.size() == 1) {
+      std::set<ObjectPtr>::const_iterator aIt;
+      for (aIt = aObjects.cbegin(); aIt != aObjects.cend(); aIt++) {
+        std::shared_ptr<SketchPlugin_Feature> aFeature =
+          std::dynamic_pointer_cast<SketchPlugin_Feature>(*aIt);
+        if (aFeature) {
+          SketchGroupPtr aGroup = findGroup(aFeature);
+
+          std::set<ObjectPtr> aFreeFeatures;
+          aGroup->underconstrainedFeatures(aFreeFeatures);
+
+          std::list<ObjectPtr> aFeatures;
+          std::set<ObjectPtr>::const_iterator aIt;
+          for (aIt = aFreeFeatures.cbegin(); aIt != aFreeFeatures.cend(); ++aIt) {
+            aFeatures.push_back(*aIt);
+          }
+
+          // TODO: send features to GUI
+          static const Events_ID anEvent = Events_Loop::eventByName(EVENT_DOF_OBJECTS);
+          ModelAPI_EventCreator::get()->sendUpdated(aFeatures, anEvent);
+          Events_Loop::loop()->flush(anEvent);
+        }
+      }
+    }
+  }
 
   // resolve constraints if needed
   bool needToUpdate = needToResolve && resolveConstraints();
index 0f518b2fae67dc6a002c2477ce333d037b0db0dc..8ef8aeb39c3415324f1622776661d9d45b2246e9 100644 (file)
@@ -129,7 +129,7 @@ public:
   std::set<ObjectPtr> getConflictingConstraints(SolverPtr theSolver) const;
 
   /// \brief Return list of features which are not fully constrained
-  virtual void getUnderconstrainedGeometry(std::set<FeaturePtr>& theFeatures) const = 0;
+  virtual void getUnderconstrainedGeometry(std::set<ObjectPtr>& theFeatures) const = 0;
 
   /// \brief Verify, the sketch contains degenerated geometry
   ///        after resolving the set of constraints