]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_PreviewPlanes.cpp
Salome HOME
#1371 Using auxilliary Sketch elements in any Feature: code improvement to separate...
[modules/shaper.git] / src / PartSet / PartSet_PreviewPlanes.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_PreviewPlanes.cpp
4 // Created:     19 Jun 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #include "PartSet_PreviewPlanes.h"
8
9 #include <ModuleBase_IWorkshop.h>
10
11 #include <ModelAPI_ResultBody.h>
12
13 #include <XGUI_Tools.h>
14 #include <XGUI_Displayer.h>
15 #include <XGUI_Workshop.h>
16
17 #include <Config_PropManager.h>
18 #include <GeomAlgoAPI_FaceBuilder.h>
19
20 #include <SketchPlugin_Sketch.h>
21
22 PartSet_PreviewPlanes::PartSet_PreviewPlanes()
23  : myPreviewDisplayed(false)
24 {
25 }
26
27 bool PartSet_PreviewPlanes::hasVisualizedBodies(ModuleBase_IWorkshop* theWorkshop)
28 {
29   bool aBodyIsVisualized = false;
30
31   XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(theWorkshop);
32   XGUI_Displayer* aDisp = aWorkshop->displayer();
33   QObjectPtrList aDisplayed = aDisp->displayedObjects();
34   foreach (ObjectPtr anObj, aDisplayed) {
35     ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
36     if (aResult.get() != NULL) {
37       aBodyIsVisualized = aResult->groupName() == ModelAPI_ResultBody::group();
38       if (aBodyIsVisualized)
39         break;
40     }
41   }
42   return aBodyIsVisualized;
43 }
44
45 void PartSet_PreviewPlanes::erasePreviewPlanes(ModuleBase_IWorkshop* theWorkshop)
46 {
47   if (myPreviewDisplayed) {
48     XGUI_Displayer* aDisp = XGUI_Tools::workshop(theWorkshop)->displayer();
49     aDisp->eraseAIS(myYZPlane, false);
50     aDisp->eraseAIS(myXZPlane, false);
51     aDisp->eraseAIS(myXYPlane, false);
52     myPreviewDisplayed = false;
53   }
54 }
55
56 void PartSet_PreviewPlanes::showPreviewPlanes(ModuleBase_IWorkshop* theWorkshop)
57 {
58   if (myPreviewDisplayed)
59     return;
60
61   if (!myYZPlane) { // If planes are not created
62     // Create Preview
63     std::shared_ptr<GeomAPI_Pnt> anOrigin(new GeomAPI_Pnt(0, 0, 0));
64     std::shared_ptr<GeomAPI_Dir> aYZDir(new GeomAPI_Dir(1, 0, 0));
65     // -1, not 1 for correct internal sketch coords (issue 898)
66     std::shared_ptr<GeomAPI_Dir> aXZDir(new GeomAPI_Dir(0, -1, 0));
67     std::shared_ptr<GeomAPI_Dir> aXYDir(new GeomAPI_Dir(0, 0, 1));
68
69     std::vector<int> aYZRGB, aXZRGB, aXYRGB;
70     aYZRGB = Config_PropManager::color("Visualization", "yz_plane_color",
71                                                         YZ_PLANE_COLOR);
72     aXZRGB = Config_PropManager::color("Visualization", "xz_plane_color",
73                                                         XZ_PLANE_COLOR);
74     aXYRGB = Config_PropManager::color("Visualization", "xy_plane_color",
75                                                         XY_PLANE_COLOR);
76     int aR[] = {aYZRGB[0], aYZRGB[1], aYZRGB[2]};
77     int aG[] = {aXZRGB[0], aXZRGB[1], aXZRGB[2]};
78     int aB[] = {aXYRGB[0], aXYRGB[1], aXYRGB[2]};
79
80     myYZPlane = createPreviewPlane(anOrigin, aYZDir, aR);
81     myXZPlane = createPreviewPlane(anOrigin, aXZDir, aG);
82     myXYPlane = createPreviewPlane(anOrigin, aXYDir, aB);
83   }
84   XGUI_Displayer* aDisp = XGUI_Tools::workshop(theWorkshop)->displayer();
85   aDisp->displayAIS(myYZPlane, true, false);
86   aDisp->displayAIS(myXZPlane, true, false);
87   aDisp->displayAIS(myXYPlane, true, false);
88   myPreviewDisplayed = true;
89 }
90
91 AISObjectPtr PartSet_PreviewPlanes::createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin, 
92                                                        std::shared_ptr<GeomAPI_Dir> theNorm, 
93                                                        const int theRGB[3])
94 {
95   double aSize = Config_PropManager::integer("Sketch planes", "planes_size", PLANE_SIZE);
96   std::shared_ptr<GeomAPI_Shape> aFace = GeomAlgoAPI_FaceBuilder::square(theOrigin, theNorm, aSize);
97   AISObjectPtr aAIS = AISObjectPtr(new GeomAPI_AISObject());
98   aAIS->createShape(aFace);
99   aAIS->setWidth(Config_PropManager::integer("Sketch planes", "planes_thickness", SKETCH_WIDTH));
100   aAIS->setColor(theRGB[0], theRGB[1], theRGB[2]);
101   return aAIS;
102 }