]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Implementation of a task "Show centers of external circular objects in current sketcher"
authorvsv <vsv@opencascade.com>
Wed, 26 Apr 2017 15:55:47 +0000 (18:55 +0300)
committervsv <vsv@opencascade.com>
Wed, 26 Apr 2017 15:56:07 +0000 (18:56 +0300)
src/GeomAPI/GeomAPI_Vertex.h
src/PartSet/PartSet_CenterPrs.cpp
src/PartSet/PartSet_CenterPrs.h
src/PartSet/PartSet_ExternalPointsMgr.cpp
src/PartSet/PartSet_ExternalPointsMgr.h
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/PartSet/PartSet_WidgetPoint2d.cpp
src/XGUI/XGUI_Tools.cpp

index c5f0dfe27144e2ff9054a7287aeefc43f26adb41..60cfca5c182b7a26fff8fd0f5a5b9a7f26a857ae 100644 (file)
@@ -38,5 +38,8 @@ public:
   bool isEqual(const std::shared_ptr<GeomAPI_Shape> theVert) const;
 };
 
+//! Pointer on the object
+typedef std::shared_ptr<GeomAPI_Vertex> GeomVertexPtr;
+
 #endif
 
index b45c2e5e7f549782974bbb9cd8a7596d7a03a000..9f7f66249df19e88fe6590e20ad3d078cae99d96 100644 (file)
 IMPLEMENT_STANDARD_RTTIEXT(PartSet_CenterPrs, AIS_Point)
 
 PartSet_CenterPrs::PartSet_CenterPrs(const ObjectPtr& theObject,
-                                     const GeomShapePtr& theEdge,
-                                     const gp_Pnt& theCenter)
+                                     const GeomEdgePtr& theEdge,
+                                     const gp_Pnt& theCenter,
+                                     ModelAPI_AttributeSelection::CenterType theType)
   : AIS_Point(new Geom_CartesianPoint(theCenter)),
   myObject(theObject),
-  myEdge(theEdge)
+  myEdge(theEdge),
+  myCenterType(theType)
 {
 }
\ No newline at end of file
index f1067eaf0b4b2ebc03ff9dbf2a4531821c9d0d3f..f9cf9232fb5a91052ca2172a0393d5b73c16f584 100644 (file)
@@ -8,7 +8,8 @@
 #define PartSet_CenterPrs_H
 
 #include <ModelAPI_Object.h>
-#include <GeomAPI_Shape.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <GeomAPI_Edge.h>
 
 #include <AIS_Point.hxx>
 #include <Standard_DefineHandle.hxx>
 
 DEFINE_STANDARD_HANDLE(PartSet_CenterPrs, AIS_Point)
 
+/**
+* \ingroup GUI
+* A presentation class for displaying of centers of external curcular objects in a sketch
+*/
 class PartSet_CenterPrs: public AIS_Point
 {
 public:
   /// Constructor
-  /// \param theResult a result object
+  /// \param theObject an object with circular edge
+  /// \param theEdge a circular edge
+  /// \param theCenter a center point of the circular edge
+  /// \param theType a type of the center
   Standard_EXPORT PartSet_CenterPrs(const ObjectPtr& theObject,
-                                    const GeomShapePtr& theEdge,
-                                    const gp_Pnt& theCenter);
+                                    const GeomEdgePtr& theEdge,
+                                    const gp_Pnt& theCenter,
+                                    ModelAPI_AttributeSelection::CenterType theType);
 
+  /// Returns an Object which contains the circular edge
   ObjectPtr object() const { return myObject; }
-  GeomShapePtr edge() const { return myEdge; }
+
+  /// Returns a circular edge shape
+  GeomEdgePtr edge() const { return myEdge; }
+
+  /// Returns type of the center
+  ModelAPI_AttributeSelection::CenterType centerType() const { return myCenterType; }
 
   DEFINE_STANDARD_RTTIEXT(PartSet_CenterPrs, AIS_Point)
+
 private:
   ObjectPtr myObject;
-  GeomShapePtr myEdge;
+  GeomEdgePtr myEdge;
+  ModelAPI_AttributeSelection::CenterType myCenterType;
 };
 
 #endif
index b638cbcd50df2204be3995d04f8a760ce6d6c178..b0faeb447c5a70281709d893de68da71e8a32547 100644 (file)
@@ -22,6 +22,7 @@
 #include <XGUI_Tools.h>
 #include <XGUI_Displayer.h>
 #include <XGUI_Workshop.h>
+#include <XGUI_SelectionMgr.h>
 
 PartSet_ExternalPointsMgr::PartSet_ExternalPointsMgr(ModuleBase_IWorkshop* theWorkshop,
                                                      const CompositeFeaturePtr& theSketch)
@@ -29,8 +30,9 @@ PartSet_ExternalPointsMgr::PartSet_ExternalPointsMgr(ModuleBase_IWorkshop* theWo
 {
   XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
-  connect(aDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjctPtr)),
+  connect(aDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)),
                       SLOT(onDisplayObject(ObjectPtr, AISObjectPtr)));
+
   connect(aDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
                       SLOT(onEraseObject(ObjectPtr, AISObjectPtr)));
 
@@ -43,6 +45,9 @@ PartSet_ExternalPointsMgr::~PartSet_ExternalPointsMgr()
   if (myPresentations.isEmpty())
     return;
   XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
+  if (!aWorkshop)
+    return;
+
   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
   QMapIterator<ObjectPtr, ListOfAIS> aIt(myPresentations);
   while (aIt.hasNext()) {
@@ -108,48 +113,55 @@ QList<std::shared_ptr<ModuleBase_ViewerPrs>> PartSet_ExternalPointsMgr::findCirc
 
 void PartSet_ExternalPointsMgr::updateCenterPresentations()
 {
+  XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
   // Return if there is no plane defined
-  if (!plane().get())
+  if (!plane().get()) {
+    connect(aWorkshop->selector(), SIGNAL(selectionChanged()),
+                                   SLOT(onSelectionChanged()));
     return;
-
-  XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
+  }
   XGUI_Displayer* aDisplayer = aWorkshop->displayer();
 
   QList<std::shared_ptr<ModuleBase_ViewerPrs>> aEdgesPrs = findCircularEdgesInPlane();
   foreach(std::shared_ptr<ModuleBase_ViewerPrs> aPrs, aEdgesPrs) {
-    GeomAPI_Edge aEdge(aPrs->shape());
-    if (aEdge.isArc() || aEdge.isCircle()) {
-      GeomCirclePtr aCircle = aEdge.circle();
+    GeomEdgePtr aEdge(new GeomAPI_Edge(aPrs->shape()));
+    ListOfAIS aList;
+    if (aEdge->isArc() || aEdge->isCircle()) {
+      GeomCirclePtr aCircle = aEdge->circle();
       GeomPointPtr aCenter = aCircle->center();
       Handle(PartSet_CenterPrs) aCentPrs =
-        new PartSet_CenterPrs(aPrs->object(), aPrs->shape(), aCenter->impl<gp_Pnt>());
+        new PartSet_CenterPrs(aPrs->object(), aEdge, aCenter->impl<gp_Pnt>(),
+                              ModelAPI_AttributeSelection::CIRCLE_CENTER);
 
       AISObjectPtr anAIS(new GeomAPI_AISObject());
       anAIS->setImpl(new Handle(AIS_InteractiveObject)(aCentPrs));
-      aDisplayer->displayAIS(anAIS, false);
-      ListOfAIS aList;
       aList.append(anAIS);
-      myPresentations[aPrs->object()] = aList;
-    } else if (aEdge.isEllipse()) {
-      GeomEllipsePtr aEllipse = aEdge.ellipse();
+    } else if (aEdge->isEllipse()) {
+      GeomEllipsePtr aEllipse = aEdge->ellipse();
       GeomPointPtr aF1 = aEllipse->firstFocus();
       GeomPointPtr aF2 = aEllipse->secondFocus();
       Handle(PartSet_CenterPrs) aF1Prs =
-        new PartSet_CenterPrs(aPrs->object(), aPrs->shape(), aF1->impl<gp_Pnt>());
+        new PartSet_CenterPrs(aPrs->object(), aEdge, aF1->impl<gp_Pnt>(),
+                              ModelAPI_AttributeSelection::ELLIPSE_FIRST_FOCUS);
       Handle(PartSet_CenterPrs) aF2Prs =
-        new PartSet_CenterPrs(aPrs->object(), aPrs->shape(), aF2->impl<gp_Pnt>());
+        new PartSet_CenterPrs(aPrs->object(), aEdge, aF2->impl<gp_Pnt>(),
+                              ModelAPI_AttributeSelection::ELLIPSE_SECOND_FOCUS);
 
-      ListOfAIS aList;
       AISObjectPtr anAIS1(new GeomAPI_AISObject());
       anAIS1->setImpl(new Handle(AIS_InteractiveObject)(aF1Prs));
-      aDisplayer->displayAIS(anAIS1, false);
       aList.append(anAIS1);
 
       AISObjectPtr anAIS2(new GeomAPI_AISObject());
       anAIS2->setImpl(new Handle(AIS_InteractiveObject)(aF2Prs));
-      aDisplayer->displayAIS(anAIS2, false);
       aList.append(anAIS2);
+    }
+    if (myPresentations.contains(aPrs->object()))
+      myPresentations[aPrs->object()].append(aList);
+    else
       myPresentations[aPrs->object()] = aList;
+    foreach(AISObjectPtr anAIS, aList) {
+      aDisplayer->displayAIS(anAIS, false);
+      aDisplayer->activateAIS(anAIS->impl<Handle(AIS_InteractiveObject)>(), TopAbs_VERTEX, false);
     }
   }
 }
@@ -166,7 +178,16 @@ void PartSet_ExternalPointsMgr::onDisplayObject(ObjectPtr theObj, AISObjectPtr t
 
 void PartSet_ExternalPointsMgr::onEraseObject(ObjectPtr theObj, AISObjectPtr theAIS)
 {
-  updateCenterPresentations();
+  if (myPresentations.contains(theObj)) {
+    XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
+    XGUI_Displayer* aDisplayer = aWorkshop->displayer();
+    ListOfAIS aList = myPresentations[theObj];
+    foreach(AISObjectPtr aAIS, aList) {
+      aDisplayer->eraseAIS(aAIS, false);
+    }
+    myPresentations.remove(theObj);
+    aDisplayer->updateViewer();
+  }
 }
 
 
@@ -177,4 +198,14 @@ bool PartSet_ExternalPointsMgr::isSketchObject(const ObjectPtr& theRes) const
     return false;
   CompositeFeaturePtr aComp = ModelAPI_Tools::compositeOwner(aFeature);
   return aComp == mySketch;
-}
\ No newline at end of file
+}
+
+void PartSet_ExternalPointsMgr::onSelectionChanged()
+{
+  if (plane().get()) {
+    XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
+    disconnect(aWorkshop->selector(), SIGNAL(selectionChanged()),
+               this, SLOT(onSelectionChanged()));
+    updateCenterPresentations();
+  }
+}
index 718902afb71f95ad002764696baefc6f64cc9d4f..8ced4b40386d3501826245f08756d9ec58d88271 100644 (file)
@@ -33,7 +33,7 @@ public:
 
   virtual ~PartSet_ExternalPointsMgr();
 
-private slots:
+public slots:
   /**
   * A slot which processes display of object
   * \param theObj the displayed object
@@ -48,6 +48,9 @@ private slots:
   */
   void onEraseObject(ObjectPtr theObj, AISObjectPtr theAIS);
 
+  // Called on selection changed
+  void onSelectionChanged();
+
 private:
   /**
   * Returns list of presentations which have displayed shapes with circular edges
@@ -62,14 +65,24 @@ private:
   /// Returns plane of the current sketch
   GeomPlanePtr plane() const;
 
+  /**
+  * Checks that the given object is an object of the current sketch
+  * \param theRes an object to check
+  * \return True if the given object is a sub-object of the current sketch
+  */
   bool isSketchObject(const ObjectPtr& theRes) const;
 
 private:
+  /// Workshop
   ModuleBase_IWorkshop* myWorkshop;
+
+  /// Current sketch
   CompositeFeaturePtr mySketch;
 
+  /// Type for list of created AIS objects
   typedef QList<AISObjectPtr> ListOfAIS;
 
+  /// Map of created AIS objects
   QMap<ObjectPtr, ListOfAIS> myPresentations;
 };
 
index 6550c77672bd2fea6af3d998fe59e09a844e5a8c..bb204073ba02c339ac5fa26a54f2103df1d386bb 100755 (executable)
@@ -889,3 +889,28 @@ bool PartSet_Tools::isAuxiliarySketchEntity(const ObjectPtr& theObject)
 
   return isAuxiliaryFeature;
 }
+
+
+ResultPtr PartSet_Tools::createFixedByExternalCenter(const ObjectPtr& theObject,
+                                                     const std::shared_ptr<GeomAPI_Edge>& theEdge,
+                                                     ModelAPI_AttributeSelection::CenterType theType,
+                                                     const CompositeFeaturePtr& theSketch,
+                                                     bool theTemporary)
+{
+  FeaturePtr aMyFeature = theSketch->addFeature(SketchPlugin_Point::ID());
+
+  if (aMyFeature) {
+    DataPtr aData = aMyFeature->data();
+    AttributeSelectionPtr anAttr =
+        std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+        (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
+
+    ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+    if (anAttr.get() && aRes.get()) {
+      anAttr->setValueCenter(aRes, theEdge, theType, theTemporary);
+      aMyFeature->execute();
+      return aMyFeature->lastResult();
+    }
+  }
+  return ResultPtr();
+}
index 1429f9d29cfdfb853b1e38a93487f8ce2202967e..8d9dce122707b3e89c23c64c8055473fe9f77864 100755 (executable)
@@ -17,6 +17,7 @@
 #include <ModelAPI_CompositeFeature.h>
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Attribute.h>
+#include <ModelAPI_AttributeSelection.h>
 
 #include <Events_Message.h>
 
@@ -265,6 +266,13 @@ public:
    * \return boolean result
    */
   static bool isAuxiliarySketchEntity(const ObjectPtr& theObject);
+
+  static ResultPtr createFixedByExternalCenter(const ObjectPtr& theObject,
+                                               const std::shared_ptr<GeomAPI_Edge>& theEdge,
+                                               ModelAPI_AttributeSelection::CenterType theType,
+                                               const CompositeFeaturePtr& theSketch,
+                                               bool theTemporary = false);
+
 };
 
 #endif
index 56b1e9852ff693f9ec2861186092d655f31269db..9d3345e1d8046cb9d6c9a5b27bdc6ba5aeb82e3c 100644 (file)
@@ -9,6 +9,7 @@
 #include <PartSet_Module.h>
 #include <PartSet_SketcherReentrantMgr.h>
 #include <PartSet_ExternalObjectsMgr.h>
+#include <PartSet_CenterPrs.h>
 
 #include <XGUI_Tools.h>
 #include <XGUI_Workshop.h>
@@ -62,6 +63,7 @@
 #include <TopoDS.hxx>
 #include <TopoDS_Vertex.hxx>
 #include <BRep_Tool.hxx>
+#include <Geom_Point.hxx>
 
 #include <cfloat>
 #include <climits>
@@ -564,6 +566,7 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo
   if (!aFirstValue.get() && myPreSelected.get()) {
     aFirstValue = myPreSelected;
   }
+
   // if we have selection and use it
   if (aFirstValue.get() && isValidSelectionCustom(aFirstValue) &&
       aFirstValue->shape().get()) { /// Trihedron Axis may be selected, but shape is empty
@@ -679,7 +682,34 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo
       }
     }
   }
-  // End of Bug dependent fragment
+  // The selection could be a center of an external circular object
+  else if (aFirstValue.get() && (!aFirstValue->interactive().IsNull())) {
+    Handle(PartSet_CenterPrs) aAIS = Handle(PartSet_CenterPrs)::DownCast(aFirstValue->interactive());
+    if (!aAIS.IsNull()) {
+      gp_Pnt aPntComp = aAIS->Component()->Pnt();
+      GeomVertexPtr aVertPtr(new GeomAPI_Vertex(aPntComp.X(), aPntComp.Y(), aPntComp.Z()));
+      TopoDS_Shape aShape = aVertPtr->impl<TopoDS_Shape>();
+
+      ResultPtr aFixedObject = PartSet_Tools::findFixedObjectByExternal(aShape, aAIS->object(), mySketch);
+      if (!aFixedObject.get())
+        aFixedObject = PartSet_Tools::createFixedByExternalCenter(aAIS->object(), aAIS->edge(),
+                                                                  aAIS->centerType(), mySketch);
+      if (aFixedObject.get())
+        setConstraintToObject(aFixedObject);
+      // fignal updated should be flushed in order to visualize possible created
+      // external objects e.g. selection of trihedron axis when input end arc point
+      updateObject(feature());
+
+      double aX, aY;
+      if (getPoint2d(aView, aShape, aX, aY)) {
+        // do not create a constraint to the point, which already used by the feature
+        // if the feature contains the point, focus is not switched
+        setPoint(aX, aY);
+      }
+      emit vertexSelected(); // it stops the reentrant operation
+      emit focusOutWidget(this);
+    }
+  }
   else {
     // A case when point is taken from mouse event
     gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWindow->v3dView());
index cd310eef0b4351b893282063740d80f47618ed6e..e057f860e3e8a7d4ad465ed672f535767ff4aed8 100644 (file)
@@ -151,7 +151,9 @@ bool canRename(const ObjectPtr& theObject, const QString& theName)
 XGUI_Workshop* workshop(ModuleBase_IWorkshop* theWorkshop)
 {
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
-  return aConnector->workshop();
+  if (aConnector)
+    return aConnector->workshop();
+  return 0;
 }
 
 }