]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
External points manager object created
authorvsv <vsv@opencascade.com>
Wed, 26 Apr 2017 11:35:32 +0000 (14:35 +0300)
committervsv <vsv@opencascade.com>
Wed, 26 Apr 2017 11:35:50 +0000 (14:35 +0300)
src/GeomAPI/GeomAPI_Circ.h
src/GeomAPI/GeomAPI_Pln.h
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_CenterPrs.cpp [new file with mode: 0644]
src/PartSet/PartSet_CenterPrs.h [new file with mode: 0644]
src/PartSet/PartSet_ExternalPointsMgr.cpp [new file with mode: 0644]
src/PartSet/PartSet_ExternalPointsMgr.h [new file with mode: 0644]
src/PartSet/PartSet_SketcherMgr.cpp
src/PartSet/PartSet_SketcherMgr.h

index 686b42edee5bb5d33e634e95fc266eac21af7b9c..ace1b64b542eb18f49bc722297669e9fc91aab55 100644 (file)
@@ -64,5 +64,8 @@ class GeomAPI_Circ : public GeomAPI_Interface
                                       double& theParameter) const;
 };
 
+//! Pointer on the object
+typedef std::shared_ptr<GeomAPI_Circ> GeomCirclePtr;
+
 #endif
 
index 704c2a0ce0ce0c9b7fcbd1b25529edede0ddeeb0..247bee78f40c75dadcffdf95ed510080bdc2f13d 100644 (file)
@@ -81,5 +81,8 @@ class GeomAPI_Pln : public GeomAPI_Interface
   std::shared_ptr<GeomAPI_Lin> intersect(const std::shared_ptr<GeomAPI_Pln> thePlane) const;
 };
 
+//! Pointer on the object
+typedef std::shared_ptr<GeomAPI_Pln> GeomPlanePtr;
+
 #endif
 
index 8dee08d11edbdb8089095c487af4e2c96491642b..3ab77b28b093bee450c4889796c4d396d75f56b9 100644 (file)
@@ -39,6 +39,8 @@ SET(PROJECT_HEADERS
     PartSet_WidgetSketchCreator.h
     PartSet_WidgetSketchLabel.h
     PartSet_WidgetSubShapeSelector.h
+       PartSet_CenterPrs.h
+       PartSet_ExternalPointsMgr.h
 )
 
 SET(PROJECT_MOC_HEADERS
@@ -58,6 +60,7 @@ SET(PROJECT_MOC_HEADERS
     PartSet_WidgetSketchCreator.h
     PartSet_WidgetSketchLabel.h
     PartSet_WidgetSubShapeSelector.h
+       PartSet_ExternalPointsMgr.h
 )
 
 SET(PROJECT_SOURCES
@@ -86,6 +89,8 @@ SET(PROJECT_SOURCES
     PartSet_WidgetSketchCreator.cpp
     PartSet_WidgetSketchLabel.cpp
     PartSet_WidgetSubShapeSelector.cpp
+       PartSet_CenterPrs.cpp
+       PartSet_ExternalPointsMgr.cpp
 )
 
 SET(PROJECT_RESOURCES
diff --git a/src/PartSet/PartSet_CenterPrs.cpp b/src/PartSet/PartSet_CenterPrs.cpp
new file mode 100644 (file)
index 0000000..b45c2e5
--- /dev/null
@@ -0,0 +1,21 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        PartSet_CenterPrs.cpp
+// Created:     25 April 2017
+// Author:      Vitaly SMETANNIKOV
+
+#include "PartSet_CenterPrs.h"
+
+#include <Geom_CartesianPoint.hxx>
+
+
+IMPLEMENT_STANDARD_RTTIEXT(PartSet_CenterPrs, AIS_Point)
+
+PartSet_CenterPrs::PartSet_CenterPrs(const ObjectPtr& theObject,
+                                     const GeomShapePtr& theEdge,
+                                     const gp_Pnt& theCenter)
+  : AIS_Point(new Geom_CartesianPoint(theCenter)),
+  myObject(theObject),
+  myEdge(theEdge)
+{
+}
\ No newline at end of file
diff --git a/src/PartSet/PartSet_CenterPrs.h b/src/PartSet/PartSet_CenterPrs.h
new file mode 100644 (file)
index 0000000..f1067ea
--- /dev/null
@@ -0,0 +1,37 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        PartSet_CenterPrs.h
+// Created:     25 April 2017
+// Author:      Vitaly SMETANNIKOV
+
+#ifndef PartSet_CenterPrs_H
+#define PartSet_CenterPrs_H
+
+#include <ModelAPI_Object.h>
+#include <GeomAPI_Shape.h>
+
+#include <AIS_Point.hxx>
+#include <Standard_DefineHandle.hxx>
+#include <gp_Pnt.hxx>
+
+DEFINE_STANDARD_HANDLE(PartSet_CenterPrs, AIS_Point)
+
+class PartSet_CenterPrs: public AIS_Point
+{
+public:
+  /// Constructor
+  /// \param theResult a result object
+  Standard_EXPORT PartSet_CenterPrs(const ObjectPtr& theObject,
+                                    const GeomShapePtr& theEdge,
+                                    const gp_Pnt& theCenter);
+
+  ObjectPtr object() const { return myObject; }
+  GeomShapePtr edge() const { return myEdge; }
+
+  DEFINE_STANDARD_RTTIEXT(PartSet_CenterPrs, AIS_Point)
+private:
+  ObjectPtr myObject;
+  GeomShapePtr myEdge;
+};
+
+#endif
diff --git a/src/PartSet/PartSet_ExternalPointsMgr.cpp b/src/PartSet/PartSet_ExternalPointsMgr.cpp
new file mode 100644 (file)
index 0000000..b638cbc
--- /dev/null
@@ -0,0 +1,180 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        PartSet_ExternalPointsMgr.cpp
+// Created:     26 April 2017
+// Author:      Vitaly SMETANNIKOV
+
+#include "PartSet_ExternalPointsMgr.h"
+#include "PartSet_CenterPrs.h"
+#include "PartSet_Tools.h"
+
+#include <ModelAPI_Tools.h>
+
+#include <ModuleBase_IWorkshop.h>
+#include <ModuleBase_ViewerPrs.h>
+
+#include <GeomAPI_Circ.h>
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Ellipse.h>
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_ShapeExplorer.h>
+
+#include <XGUI_Tools.h>
+#include <XGUI_Displayer.h>
+#include <XGUI_Workshop.h>
+
+PartSet_ExternalPointsMgr::PartSet_ExternalPointsMgr(ModuleBase_IWorkshop* theWorkshop,
+                                                     const CompositeFeaturePtr& theSketch)
+  : QObject(theWorkshop), myWorkshop(theWorkshop), mySketch(theSketch)
+{
+  XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
+  XGUI_Displayer* aDisplayer = aWorkshop->displayer();
+  connect(aDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjctPtr)),
+                      SLOT(onDisplayObject(ObjectPtr, AISObjectPtr)));
+  connect(aDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)),
+                      SLOT(onEraseObject(ObjectPtr, AISObjectPtr)));
+
+  updateCenterPresentations();
+}
+
+
+PartSet_ExternalPointsMgr::~PartSet_ExternalPointsMgr()
+{
+  if (myPresentations.isEmpty())
+    return;
+  XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
+  XGUI_Displayer* aDisplayer = aWorkshop->displayer();
+  QMapIterator<ObjectPtr, ListOfAIS> aIt(myPresentations);
+  while (aIt.hasNext()) {
+    aIt.next();
+    ListOfAIS aAISList = aIt.value();
+    foreach (AISObjectPtr aAIS, aAISList) {
+      aDisplayer->eraseAIS(aAIS, false);
+    }
+  }
+}
+
+
+//******************************************************
+QList<std::shared_ptr<ModuleBase_ViewerPrs>> PartSet_ExternalPointsMgr::findCircularEdgesInPlane()
+{
+  QList<std::shared_ptr<ModuleBase_ViewerPrs>> aResult;
+  XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
+  XGUI_Displayer* aDisplayer = aWorkshop->displayer();
+  QObjectPtrList aDispObjects = aDisplayer->displayedObjects();
+
+  std::shared_ptr<GeomAPI_Pln> aPlane = plane();
+  foreach(ObjectPtr aObj, aDispObjects) {
+    if (myPresentations.contains(aObj))
+      continue;
+
+    // Do not process objects of the current sketch
+    if (isSketchObject(aObj))
+      continue;
+
+    ResultPtr aResObj = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
+    if (aResObj.get()) {
+      GeomShapePtr aShape = aResObj->shape();
+      if (aShape.get()) {
+        GeomAPI_ShapeExplorer aExplorer(aShape, GeomAPI_Shape::EDGE);
+        for(; aExplorer.more(); aExplorer.next()) {
+          GeomShapePtr aEdgeShape = aExplorer.current();
+          GeomAPI_Edge anEdge(aEdgeShape);
+          if ((anEdge.isCircle() || anEdge.isArc() || anEdge.isEllipse()) &&
+               anEdge.isInPlane(aPlane)) {
+            bool isContains = false;
+            // Check that edge is not already used.
+            // It is possible that the same edge will be taken from different faces
+            foreach(std::shared_ptr<ModuleBase_ViewerPrs> aPrs, aResult) {
+              GeomAPI_Edge aUsedEdge(aPrs->shape());
+              if (aUsedEdge.isEqual(aEdgeShape)) {
+                isContains = true;
+                break;
+              }
+            }
+            if (!isContains) {
+              std::shared_ptr<ModuleBase_ViewerPrs>
+                aPrs(new ModuleBase_ViewerPrs(aResObj, aEdgeShape));
+              aResult.append(aPrs);
+            }
+          }
+        }
+      }
+    }
+  }
+  return aResult;
+}
+
+
+void PartSet_ExternalPointsMgr::updateCenterPresentations()
+{
+  // Return if there is no plane defined
+  if (!plane().get())
+    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();
+      GeomPointPtr aCenter = aCircle->center();
+      Handle(PartSet_CenterPrs) aCentPrs =
+        new PartSet_CenterPrs(aPrs->object(), aPrs->shape(), aCenter->impl<gp_Pnt>());
+
+      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();
+      GeomPointPtr aF1 = aEllipse->firstFocus();
+      GeomPointPtr aF2 = aEllipse->secondFocus();
+      Handle(PartSet_CenterPrs) aF1Prs =
+        new PartSet_CenterPrs(aPrs->object(), aPrs->shape(), aF1->impl<gp_Pnt>());
+      Handle(PartSet_CenterPrs) aF2Prs =
+        new PartSet_CenterPrs(aPrs->object(), aPrs->shape(), aF2->impl<gp_Pnt>());
+
+      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);
+      myPresentations[aPrs->object()] = aList;
+    }
+  }
+}
+
+std::shared_ptr<GeomAPI_Pln> PartSet_ExternalPointsMgr::plane() const
+{
+  return PartSet_Tools::sketchPlane(mySketch);
+}
+
+void PartSet_ExternalPointsMgr::onDisplayObject(ObjectPtr theObj, AISObjectPtr theAIS)
+{
+  updateCenterPresentations();
+}
+
+void PartSet_ExternalPointsMgr::onEraseObject(ObjectPtr theObj, AISObjectPtr theAIS)
+{
+  updateCenterPresentations();
+}
+
+
+bool PartSet_ExternalPointsMgr::isSketchObject(const ObjectPtr& theRes) const
+{
+  FeaturePtr aFeature = ModelAPI_Feature::feature(theRes);
+  if (!aFeature.get())
+    return false;
+  CompositeFeaturePtr aComp = ModelAPI_Tools::compositeOwner(aFeature);
+  return aComp == mySketch;
+}
\ No newline at end of file
diff --git a/src/PartSet/PartSet_ExternalPointsMgr.h b/src/PartSet/PartSet_ExternalPointsMgr.h
new file mode 100644 (file)
index 0000000..718902a
--- /dev/null
@@ -0,0 +1,76 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        PartSet_ExternalPointsMgr.h
+// Created:     26 April 2017
+// Author:      Vitaly SMETANNIKOV
+
+#ifndef PartSet_ExternalPointsMgr_H
+#define PartSet_ExternalPointsMgr_H
+
+
+#include <ModelAPI_CompositeFeature.h>
+#include <ModelAPI_Result.h>
+#include <GeomAPI_Pln.h>
+#include <GeomAPI_AISObject.h>
+
+#include <QObject>
+#include <QMap>
+
+class ModuleBase_ViewerPrs;
+class ModuleBase_IWorkshop;
+
+
+/**
+* \ingroup Modules
+* A class to manage display of presentations of center points of circular
+* edges outside of a current sketcher
+*/
+class PartSet_ExternalPointsMgr: public QObject
+{
+  Q_OBJECT
+public:
+  PartSet_ExternalPointsMgr(ModuleBase_IWorkshop* theWorkshop, const CompositeFeaturePtr& theSketch);
+
+  virtual ~PartSet_ExternalPointsMgr();
+
+private slots:
+  /**
+  * A slot which processes display of object
+  * \param theObj the displayed object
+  * \param theAIS its presentation
+  */
+  void onDisplayObject(ObjectPtr theObj, AISObjectPtr theAIS);
+
+  /**
+  * A slot which processes erase of object
+  * \param theObj the displayed object
+  * \param theAIS its presentation
+  */
+  void onEraseObject(ObjectPtr theObj, AISObjectPtr theAIS);
+
+private:
+  /**
+  * Returns list of presentations which have displayed shapes with circular edges
+  * (circles, arcs) which are in pane of of the given sketch
+  * \param theSketch - the sketch
+  */
+  QList<std::shared_ptr<ModuleBase_ViewerPrs>> findCircularEdgesInPlane();
+
+  /// Creates presentations of centers
+  void updateCenterPresentations();
+
+  /// Returns plane of the current sketch
+  GeomPlanePtr plane() const;
+
+  bool isSketchObject(const ObjectPtr& theRes) const;
+
+private:
+  ModuleBase_IWorkshop* myWorkshop;
+  CompositeFeaturePtr mySketch;
+
+  typedef QList<AISObjectPtr> ListOfAIS;
+
+  QMap<ObjectPtr, ListOfAIS> myPresentations;
+};
+
+#endif
\ No newline at end of file
index 9f8e4cf21d37471a3a9b90ce9947560c1421cb90..4fe035efd7184a84e5294f5a2a854537296df591 100755 (executable)
@@ -12,6 +12,7 @@
 #include "PartSet_WidgetSketchLabel.h"
 #include "PartSet_WidgetEditor.h"
 #include "PartSet_ResultSketchPrs.h"
+#include "PartSet_ExternalPointsMgr.h"
 
 #include <XGUI_ModuleConnector.h>
 #include <XGUI_Displayer.h>
@@ -138,7 +139,7 @@ PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
   : QObject(theModule), myModule(theModule), myIsEditLaunching(false), myIsDragging(false),
     myDragDone(false), myIsMouseOverWindow(false),
     myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
-    myIsPopupMenuActive(false)
+    myIsPopupMenuActive(false), myExternalPointsMgr(0)
 {
   ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
   ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
@@ -985,6 +986,8 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
   // plane filter
   if (aPln.get())
     aConnector->activateModuleSelectionModes();
+
+  myExternalPointsMgr = new PartSet_ExternalPointsMgr(myModule->workshop(), myCurrentSketch);
 }
 
 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
@@ -994,6 +997,11 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
   myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
   myIsConstraintsShown[PartSet_Tools::Expressions] = false;
 
+  if (myExternalPointsMgr) {
+    delete myExternalPointsMgr;
+    myExternalPointsMgr = 0;
+  }
+
   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
 
   DataPtr aData = myCurrentSketch->data();
index b1ab8cb4c0a0f2e52cb277eacea35b683ede4d59..078901ca5c2355e9473ffe7e9bd321b7380d3079 100644 (file)
@@ -36,6 +36,7 @@ class ModuleBase_ModelWidget;
 class ModuleBase_Operation;
 class XGUI_OperationMgr;
 class XGUI_Workshop;
+class PartSet_ExternalPointsMgr;
 
 class AIS_InteractiveObject;
 
@@ -418,6 +419,8 @@ private:
   bool myPreviousUpdateViewerEnabled;
 
   QMap<PartSet_Tools::ConstraintVisibleState, bool> myIsConstraintsShown;
+
+  PartSet_ExternalPointsMgr* myExternalPointsMgr;
 };