Salome HOME
#1857 In the Sketcher, ability to zoom the view from a given size
[modules/shaper.git] / src / PartSet / PartSet_PreviewPlanes.cpp
index 424deec9d0356aeeed7f034cc0d266b4f86ae6cf..344f20ed9782150e08c95f572a50c3f22e9d1637 100755 (executable)
@@ -9,6 +9,7 @@
 #include <ModuleBase_IWorkshop.h>
 
 #include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultConstruction.h>
 
 #include <XGUI_Tools.h>
 #include <XGUI_Displayer.h>
@@ -33,10 +34,15 @@ bool PartSet_PreviewPlanes::hasVisualizedBodies(ModuleBase_IWorkshop* theWorksho
   QObjectPtrList aDisplayed = aDisp->displayedObjects();
   foreach (ObjectPtr anObj, aDisplayed) {
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
-    if (aResult.get() != NULL) {
-      aBodyIsVisualized = aResult->groupName() == ModelAPI_ResultBody::group();
-      if (aBodyIsVisualized)
-        break;
+    // result constructions should not be taken as a body
+    if (aResult.get() != NULL && aResult->groupName() == ModelAPI_ResultBody::group()) {
+      GeomShapePtr aShape = aResult->shape();
+      if (aShape.get()) {
+        // vertices, edges should not be taken as a body
+        aBodyIsVisualized = aShape->shapeType() <= GeomAPI_Shape::FACE;
+        if (aBodyIsVisualized)
+          break;
+      }
     }
   }
   return aBodyIsVisualized;
@@ -53,14 +59,27 @@ bool PartSet_PreviewPlanes::hasVisualizedSketch(ModuleBase_IWorkshop* theWorksho
     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
     if (aResult.get() != NULL) {
       FeaturePtr aFeature = ModelAPI_Feature::feature(aResult);
-      aSketchIsVisualized = aFeature.get() && aFeature->getKind() == SketchPlugin_Sketch::ID();
-      if (aSketchIsVisualized)
-        break;
+      if (aFeature.get() && aFeature->getKind() == SketchPlugin_Sketch::ID()) {
+        ResultConstructionPtr aCResult =  std::dynamic_pointer_cast<ModelAPI_ResultConstruction>
+                                                                                      (aResult);
+        if (aCResult.get() && aCResult->facesNum() > 0) {
+          aSketchIsVisualized = true;
+          break;
+        }
+      }
+      break;
     }
   }
   return aSketchIsVisualized;
 }
 
+bool PartSet_PreviewPlanes::isPreviewShape(std::shared_ptr<GeomAPI_Shape> theShape)
+{
+  return (myYZPlane->getShape()->isEqual(theShape) ||
+          myXZPlane->getShape()->isEqual(theShape) ||
+          myXYPlane->getShape()->isEqual(theShape));
+}
+
 void PartSet_PreviewPlanes::erasePreviewPlanes(ModuleBase_IWorkshop* theWorkshop)
 {
   if (myPreviewDisplayed) {
@@ -107,15 +126,16 @@ void PartSet_PreviewPlanes::showPreviewPlanes(ModuleBase_IWorkshop* theWorkshop)
   myPreviewDisplayed = true;
 }
 
-AISObjectPtr PartSet_PreviewPlanes::createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin, 
-                                                       std::shared_ptr<GeomAPI_Dir> theNorm, 
+AISObjectPtr PartSet_PreviewPlanes::createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin,
+                                                       std::shared_ptr<GeomAPI_Dir> theNorm,
                                                        const int theRGB[3])
 {
-  double aSize = Config_PropManager::integer("Sketch planes", "planes_size", PLANE_SIZE);
-  std::shared_ptr<GeomAPI_Shape> aFace = GeomAlgoAPI_FaceBuilder::square(theOrigin, theNorm, aSize);
+  double aSize = Config_PropManager::integer(SKETCH_TAB_NAME, "planes_size", PLANE_SIZE);
+  std::shared_ptr<GeomAPI_Shape> aFace =
+    GeomAlgoAPI_FaceBuilder::squareFace(theOrigin, theNorm, aSize);
   AISObjectPtr aAIS = AISObjectPtr(new GeomAPI_AISObject());
   aAIS->createShape(aFace);
-  aAIS->setWidth(Config_PropManager::integer("Sketch planes", "planes_thickness", SKETCH_WIDTH));
+  aAIS->setWidth(Config_PropManager::integer(SKETCH_TAB_NAME, "planes_thickness", SKETCH_WIDTH));
   aAIS->setColor(theRGB[0], theRGB[1], theRGB[2]);
   return aAIS;
 }