1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_PreviewPlanes.cpp
4 // Created: 19 Jun 2015
5 // Author: Natalia ERMOLAEVA
7 #include "PartSet_PreviewPlanes.h"
9 #include <ModuleBase_IWorkshop.h>
11 #include <ModelAPI_ResultBody.h>
13 #include <XGUI_Tools.h>
14 #include <XGUI_Displayer.h>
15 #include <XGUI_Workshop.h>
17 #include <Config_PropManager.h>
18 #include <GeomAlgoAPI_FaceBuilder.h>
20 #include <SketchPlugin_Sketch.h>
22 PartSet_PreviewPlanes::PartSet_PreviewPlanes()
23 : myPreviewDisplayed(false)
27 bool PartSet_PreviewPlanes::hasVisualizedBodies(ModuleBase_IWorkshop* theWorkshop)
29 bool aBodyIsVisualized = false;
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)
42 return aBodyIsVisualized;
45 void PartSet_PreviewPlanes::erasePreviewPlanes(ModuleBase_IWorkshop* theWorkshop)
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;
56 void PartSet_PreviewPlanes::showPreviewPlanes(ModuleBase_IWorkshop* theWorkshop)
58 if (myPreviewDisplayed)
61 if (!myYZPlane) { // If planes are not created
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));
69 std::vector<int> aYZRGB, aXZRGB, aXYRGB;
70 aYZRGB = Config_PropManager::color("Visualization", "yz_plane_color",
72 aXZRGB = Config_PropManager::color("Visualization", "xz_plane_color",
74 aXYRGB = Config_PropManager::color("Visualization", "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]};
80 myYZPlane = createPreviewPlane(anOrigin, aYZDir, aR);
81 myXZPlane = createPreviewPlane(anOrigin, aXZDir, aG);
82 myXYPlane = createPreviewPlane(anOrigin, aXYDir, aB);
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;
91 AISObjectPtr PartSet_PreviewPlanes::createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin,
92 std::shared_ptr<GeomAPI_Dir> theNorm,
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]);