- XGUI_Selection* aSelection = myWorkshop->selector()->selection();
- QList<ModuleBase_ViewerPrs> aSelected = aSelection->getSelected();
- if (!aSelected.empty()) {
- ModuleBase_ViewerPrs aPrs = aSelected.first();
- TopoDS_Shape aShape = aPrs.shape();
- if (!aShape.IsNull()) {
- std::shared_ptr<GeomAPI_Dir> aDir = setSketchPlane(aShape);
- if (aDir) {
- erasePreviewPlanes();
-
- if (aPrs.object() && (feature() != aPrs.object())) {
- DataPtr aData = feature()->data();
- AttributeSelectionPtr aSelAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
- (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID()));
- if (aSelAttr) {
- ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aPrs.object());
- if (aRes) {
- GeomShapePtr aShapePtr(new GeomAPI_Shape());
- aShapePtr->setImpl(new TopoDS_Shape(aShape));
- aSelAttr->setValue(aRes, aShapePtr);
- }
- }
- } else
- myWorkshop->viewer()->setViewProjection(aDir->x(), aDir->y(), aDir->z());
-
- // Clear text in the label
- myLabel->setText("");
- myLabel->setToolTip("");
- disconnect(myWorkshop->selector(), SIGNAL(selectionChanged()),
- this, SLOT(onPlaneSelected()));
-
- // Clear selection mode and define sketching mode
- XGUI_Displayer* aDisp = myWorkshop->displayer();
- aDisp->removeSelectionFilter(myFaceFilter);
- //aDisp->closeLocalContexts();
- emit planeSelected(plane());
- setSketchingMode();
-
- // Update sketcher actions
- XGUI_ActionsMgr* anActMgr = myWorkshop->actionsMgr();
- anActMgr->update();
+ // 1. hide main planes if they have been displayed
+ erasePreviewPlanes();
+ // 2. if the planes were displayed, change the view projection
+ TopoDS_Shape aShape = thePrs.shape();
+ std::shared_ptr<GeomAPI_Shape> aGShape;
+ std::shared_ptr<GeomAPI_Shape> aBaseShape;
+
+ DataPtr aData = feature()->data();
+ AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+ (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
+
+ // selection happens in OCC viewer
+ if (!aShape.IsNull()) {
+ aGShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape());
+ aGShape->setImpl(new TopoDS_Shape(aShape));
+
+ if (aSelAttr && aSelAttr->context()) {
+ aBaseShape = aSelAttr->context()->shape();
+ }
+ }
+ else { // selection happens in OCC viewer(on body) of in the OB browser
+ if (aSelAttr) {
+ aGShape = aSelAttr->value();
+ }
+ }
+ if (aGShape.get() != NULL) {
+ // get plane parameters
+ std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aGShape);
+ std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
+ gp_XYZ aXYZ = aDir->impl<gp_Dir>().XYZ();
+ double aTwist = 0.0;
+
+ // orienting projection
+ if(aBaseShape.get() != NULL) {
+ std::shared_ptr<GeomAPI_Pnt> aCenterPnt = GeomAlgoAPI_ShapeTools::centreOfMass(aGShape);
+ gp_Pnt aPnt = aCenterPnt->impl<gp_Pnt>();
+ aPnt.Translate(aDir->impl<gp_Dir>().XYZ() * (10 * Precision::Confusion()));
+
+ BRepClass3d_SolidClassifier aClassifier;
+ aClassifier.Load(aBaseShape->impl<TopoDS_Shape>());
+ aClassifier.Perform(aPnt, Precision::Confusion());
+
+ if(aClassifier.State() == TopAbs_IN) {
+ aXYZ.Reverse();