+
+void PartSet_WidgetSketchLabel::showPreviewPlanes()
+{
+ if (myPreviewDisplayed)
+ return;
+
+ if (!myYZPlane) { // If planes are not created
+ // Create Preview
+ std::shared_ptr<GeomAPI_Pnt> anOrigin(new GeomAPI_Pnt(0, 0, 0));
+ std::shared_ptr<GeomAPI_Dir> aYZDir(new GeomAPI_Dir(1, 0, 0));
+ std::shared_ptr<GeomAPI_Dir> aXZDir(new GeomAPI_Dir(0, 1, 0));
+ std::shared_ptr<GeomAPI_Dir> aXYDir(new GeomAPI_Dir(0, 0, 1));
+
+ int aR[] = {255, 0, 0};
+ int aG[] = {0, 255, 0};
+ int aB[] = {0, 0, 255};
+
+ myYZPlane = createPreviewPlane(anOrigin, aYZDir, aR);
+ myXZPlane = createPreviewPlane(anOrigin, aXZDir, aG);
+ myXYPlane = createPreviewPlane(anOrigin, aXYDir, aB);
+ }
+ XGUI_Displayer* aDisp = myWorkshop->displayer();
+ aDisp->displayAIS(myYZPlane, false);
+ aDisp->displayAIS(myXZPlane, false);
+ aDisp->displayAIS(myXYPlane, false);
+ myPreviewDisplayed = true;
+}
+
+
+AISObjectPtr PartSet_WidgetSketchLabel::createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin,
+ std::shared_ptr<GeomAPI_Dir> theNorm,
+ const int theRGB[3])
+{
+ double aSize = Config_PropManager::integer("Sketch planes", "Size of planes", PLANE_SIZE);
+ std::shared_ptr<GeomAPI_Shape> aFace = GeomAlgoAPI_FaceBuilder::square(theOrigin, theNorm, aSize);
+ AISObjectPtr aAIS = AISObjectPtr(new GeomAPI_AISObject());
+ aAIS->createShape(aFace);
+ aAIS->setWidth(Config_PropManager::integer("Sketch planes", "planes_thickness", SKETCH_WIDTH));
+ aAIS->setColor(theRGB[0], theRGB[1], theRGB[2]);
+ return aAIS;
+}
+
+
+std::shared_ptr<GeomAPI_Dir> PartSet_WidgetSketchLabel::setSketchPlane(const TopoDS_Shape& theShape)
+{
+ if (theShape.IsNull())
+ return std::shared_ptr<GeomAPI_Dir>();
+
+ // get selected shape
+ std::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
+ aGShape->setImpl(new TopoDS_Shape(theShape));
+
+ // get plane parameters
+ std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
+
+ // set plane parameters to feature
+ std::shared_ptr<ModelAPI_Data> aData = feature()->data();
+ double anA, aB, aC, aD;
+ aPlane->coefficients(anA, aB, aC, aD);
+
+ // calculate attributes of the sketch
+ std::shared_ptr<GeomAPI_Dir> aNormDir(new GeomAPI_Dir(anA, aB, aC));
+ std::shared_ptr<GeomAPI_XYZ> aCoords = aNormDir->xyz();
+ std::shared_ptr<GeomAPI_XYZ> aZero(new GeomAPI_XYZ(0, 0, 0));
+ aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero));
+ std::shared_ptr<GeomAPI_Pnt> anOrigPnt(new GeomAPI_Pnt(aCoords));
+ // X axis is preferable to be dirX on the sketch
+ const double tol = Precision::Confusion();
+ bool isX = fabs(anA - 1.0) < tol && fabs(aB) < tol && fabs(aC) < tol;
+ std::shared_ptr<GeomAPI_Dir> aTempDir(
+ isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0));
+ std::shared_ptr<GeomAPI_Dir> aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir)));
+ std::shared_ptr<GeomAPI_Dir> aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir)));
+
+ std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+ aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+ anOrigin->setValue(anOrigPnt);
+ std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+ aNormal->setValue(aNormDir);
+ std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
+ aDirX->setValue(aXDir);
+ std::shared_ptr<GeomDataAPI_Dir> aDirY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(SketchPlugin_Sketch::DIRY_ID()));
+ aDirY->setValue(aYDir);
+ std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
+ return aDir;
+}
+
+
+void PartSet_WidgetSketchLabel::setSketchingMode()
+{
+ qDebug("### Set sketching mode");
+
+ XGUI_Displayer* aDisp = myWorkshop->displayer();
+ // Clear standard selection modes if they are defined
+ //aDisp->activateObjects(aModes);
+ //aDisp->openLocalContext();
+
+ // Get default selection modes
+ QIntList aModes;
+ aModes.append(AIS_DSM_Text);
+ aModes.append(AIS_DSM_Line);
+ aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_VERTEX));
+ aModes.append(AIS_Shape::SelectionMode((TopAbs_ShapeEnum) TopAbs_EDGE));
+
+ aDisp->activateObjects(aModes);
+}