Salome HOME
Add ellipse data type
[modules/shaper.git] / src / PartSet / PartSet_WidgetSketchLabel.cpp
index bdf32db5416f40a1a99098b50d5841fd250083f1..b3a05a35c0db0141777a835669dfe9c108d36774 100644 (file)
@@ -34,6 +34,8 @@
 #include <GeomDataAPI_Dir.h>
 #include <GeomAPI_XYZ.h>
 #include <GeomAPI_Face.h>
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_ShapeExplorer.h>
 
 #include <SketchPlugin_Sketch.h>
 #include <SketcherPrs_Tools.h>
@@ -310,9 +312,6 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs
     bool aRotate = Config_PropManager::boolean(SKETCH_TAB_NAME, "rotate_to_plane");
     if (aRotate) {
       myWorkshop->viewer()->setViewProjection(aXYZ.X(), aXYZ.Y(), aXYZ.Z(), aTwist);
-      PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
-      if (aModule)
-        aModule->onViewTransformed();
     }
     QString aSizeOfViewStr = mySizeOfView->text();
     if (!aSizeOfViewStr.isEmpty()) {
@@ -328,6 +327,9 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs
         }
       }
     }
+    PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
+    if (aModule)
+      aModule->onViewTransformed();
   }
   // 3. Clear text in the label
   myStackWidget->setCurrentIndex(1);
@@ -348,7 +350,9 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs
 
   // 6. Update sketcher actions
   XGUI_ActionsMgr* anActMgr = aWorkshop->actionsMgr();
+
   myWorkshop->updateCommandStatus();
+  aWorkshop->selector()->clearSelection();
   myWorkshop->viewer()->update();
 }
 
@@ -524,6 +528,9 @@ void PartSet_WidgetSketchLabel::activateSelection(bool toActivate)
     QIntList aModes;
     std::shared_ptr<GeomAPI_Pln> aPlane = plane();
     if (aPlane.get()) {
+      //QList<std::shared_ptr<ModuleBase_ViewerPrs>> aEdges = findCircularEdgesInPlane();
+      //foreach(std::shared_ptr<ModuleBase_ViewerPrs> aPrs, aEdges) {
+      //}
       myWorkshop->module()->activeSelectionModes(aModes);
     }
     else {
@@ -603,3 +610,47 @@ void PartSet_WidgetSketchLabel::onSetPlaneView()
       aModule->onViewTransformed();
   }
 }
+
+
+//******************************************************
+QList<std::shared_ptr<ModuleBase_ViewerPrs>> PartSet_WidgetSketchLabel::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) {
+    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 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;
+}