Salome HOME
#1857 In the Sketcher, ability to zoom the view from a given size
[modules/shaper.git] / src / PartSet / PartSet_WidgetSketchLabel.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_WidgetSketchLabel.cpp
4 // Created:     07 July 2014
5 // Author:      Vitaly SMETANNIKOV
6
7 #include "PartSet_WidgetSketchLabel.h"
8 #include "PartSet_Tools.h"
9 #include "PartSet_Module.h"
10 #include "PartSet_PreviewPlanes.h"
11
12 #include "SketchPlugin_SketchEntity.h"
13
14 #include <XGUI_Workshop.h>
15 #include <XGUI_Displayer.h>
16 #include <XGUI_SelectionMgr.h>
17 #include <XGUI_Selection.h>
18 #include <XGUI_ViewerProxy.h>
19 #include <XGUI_ActionsMgr.h>
20 #include <XGUI_Tools.h>
21 #include <XGUI_ModuleConnector.h>
22
23 #include <ModuleBase_Operation.h>
24 #include <ModuleBase_ViewerPrs.h>
25 #include <ModuleBase_Tools.h>
26 #include <ModuleBase_IModule.h>
27
28 #include <ModelAPI_ResultBody.h>
29 #include <ModelAPI_Tools.h>
30
31 #include <GeomAlgoAPI_FaceBuilder.h>
32 #include <GeomAlgoAPI_ShapeTools.h>
33 #include <GeomDataAPI_Point.h>
34 #include <GeomDataAPI_Dir.h>
35 #include <GeomAPI_XYZ.h>
36 #include <GeomAPI_Face.h>
37
38 #include <SketchPlugin_Sketch.h>
39 #include <SketcherPrs_Tools.h>
40
41 #include <Precision.hxx>
42 #include <gp_Pln.hxx>
43 #include <gp_Pnt.hxx>
44 #include <gp_Dir.hxx>
45 #include <AIS_Shape.hxx>
46 #include <AIS_DimensionSelectionMode.hxx>
47 #include <Bnd_Box.hxx>
48
49 #include <Config_WidgetAPI.h>
50 #include <Config_PropManager.h>
51
52 #include <QLabel>
53 #include <QApplication>
54 #include <QVBoxLayout>
55 #include <QHBoxLayout>
56 #include <QCheckBox>
57 #include <QGroupBox>
58 #include <QPushButton>
59 #include <QStackedWidget>
60 #include <QLineEdit>
61 #include <QDoubleValidator>
62
63 #ifndef DBL_MAX
64 #define DBL_MAX 1.7976931348623158e+308
65 #endif
66
67 PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent,
68                         ModuleBase_IWorkshop* theWorkshop,
69                         const Config_WidgetAPI* theData,
70                         const QMap<PartSet_Tools::ConstraintVisibleState, bool>& toShowConstraints)
71 : ModuleBase_WidgetValidated(theParent, theWorkshop, theData)
72 {
73   QVBoxLayout* aLayout = new QVBoxLayout(this);
74   ModuleBase_Tools::zeroMargins(aLayout);
75
76   myStackWidget = new QStackedWidget(this);
77   myStackWidget->setContentsMargins(0,0,0,0);
78   aLayout->addWidget(myStackWidget);
79
80   // Define label for plane selection
81   QWidget* aFirstWgt = new QWidget(this);
82
83   // Size of the View control
84   mySizeOfViewWidget = new QWidget(aFirstWgt);
85   QHBoxLayout* aSizeLayout = new QHBoxLayout(mySizeOfViewWidget);
86   aSizeLayout->addWidget(new QLabel("Size of the view", aFirstWgt));
87   mySizeOfView = new QLineEdit(aFirstWgt);
88
89   QDoubleValidator* aValidator = new QDoubleValidator(0, DBL_MAX, 12, mySizeOfView);
90   aValidator->setLocale(ModuleBase_Tools::doubleLocale());
91   aValidator->setNotation(QDoubleValidator::StandardNotation);
92   mySizeOfView->setValidator(aValidator);
93   aSizeLayout->addWidget(mySizeOfView);
94
95   QString aText = QString::fromStdString(theData->getProperty("title"));
96   QLabel* aLabel = new QLabel(aText, aFirstWgt);
97   aLabel->setWordWrap(true);
98   QString aTooltip = QString::fromStdString(theData->getProperty("tooltip"));
99   aLabel->setToolTip(aTooltip);
100   aLabel->setIndent(5);
101
102   aLayout = new QVBoxLayout(aFirstWgt);
103   ModuleBase_Tools::zeroMargins(aLayout);
104   aLayout->addWidget(mySizeOfViewWidget);
105   aLayout->addWidget(aLabel);
106
107   myStackWidget->addWidget(aFirstWgt);
108
109   // Define widget for sketch manmagement
110   QWidget* aSecondWgt = new QWidget(this);
111   aLayout = new QVBoxLayout(aSecondWgt);
112   ModuleBase_Tools::zeroMargins(aLayout);
113
114   QGroupBox* aViewBox = new QGroupBox(tr("Sketcher plane"), this);
115   QVBoxLayout* aViewLayout = new QVBoxLayout(aViewBox);
116
117   myViewInverted = new QCheckBox(tr("Reversed"), aViewBox);
118   aViewLayout->addWidget(myViewInverted);
119
120   QPushButton* aSetViewBtn =
121     new QPushButton(QIcon(":icons/plane_view.png"), tr("Set plane view"), aViewBox);
122   connect(aSetViewBtn, SIGNAL(clicked(bool)), this, SLOT(onSetPlaneView()));
123   aViewLayout->addWidget(aSetViewBtn);
124
125   aLayout->addWidget(aViewBox);
126
127   QMap<PartSet_Tools::ConstraintVisibleState, QString> aStates;
128   aStates[PartSet_Tools::Geometrical] = tr("Show geometrical constraints");
129   aStates[PartSet_Tools::Dimensional] = tr("Show dimensional constraints");
130   aStates[PartSet_Tools::Expressions] = tr("Show existing expressions");
131
132   QMap<PartSet_Tools::ConstraintVisibleState, QString>::const_iterator anIt = aStates.begin(),
133                                                         aLast = aStates.end();
134   for (; anIt != aLast; anIt++) {
135     QCheckBox* aShowConstraints = new QCheckBox(anIt.value(), this);
136     connect(aShowConstraints, SIGNAL(toggled(bool)), this, SLOT(onShowConstraint(bool)));
137     aLayout->addWidget(aShowConstraints);
138
139     PartSet_Tools::ConstraintVisibleState aState = anIt.key();
140     myShowConstraints[aState] = aShowConstraints;
141
142     if (toShowConstraints.contains(aState))
143       aShowConstraints->setChecked(toShowConstraints[aState]);
144   }
145
146   myStackWidget->addWidget(aSecondWgt);
147   //setLayout(aLayout);
148
149   myPreviewPlanes = new PartSet_PreviewPlanes();
150 }
151
152 PartSet_WidgetSketchLabel::~PartSet_WidgetSketchLabel()
153 {
154 }
155
156 bool PartSet_WidgetSketchLabel::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValues,
157                                              const bool theToValidate)
158 {
159   // do not use the given selection if the plane of the sketch has been already set.
160   // If this check is absent, a selected plane in the viewer can be set in the sketch
161   // even if the sketch is built on another plane.
162   if (plane().get())
163     return true;
164
165   ModuleBase_ViewerPrsPtr aPrs = theValues.first();
166   bool aDone = setSelectionInternal(theValues, theToValidate);
167   if (aDone)
168     updateByPlaneSelected(aPrs);
169   return aDone;
170 }
171
172 QList<QWidget*> PartSet_WidgetSketchLabel::getControls() const
173 {
174   QList<QWidget*> aResult;
175   aResult << myStackWidget;
176   return aResult;
177 }
178
179 void PartSet_WidgetSketchLabel::onSelectionChanged()
180 {
181   QList<ModuleBase_ViewerPrsPtr> aSelected = getFilteredSelected();
182
183   if (aSelected.empty())
184     return;
185   ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
186   bool aDone = setSelectionInternal(aSelected, false);
187   if (aDone) {
188     updateByPlaneSelected(aPrs);
189     updateObject(myFeature);
190   }
191 }
192
193 void PartSet_WidgetSketchLabel::onShowConstraint(bool theOn)
194 {
195   QCheckBox* aSenderCheckBox = qobject_cast<QCheckBox*>(sender());
196
197   QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*>::const_iterator
198                           anIt = myShowConstraints.begin(), aLast = myShowConstraints.end();
199
200   PartSet_Tools::ConstraintVisibleState aState = PartSet_Tools::Geometrical;
201   bool aFound = false;
202   for (; anIt != aLast && !aFound; anIt++) {
203     aFound = anIt.value() == aSenderCheckBox;
204     if (aFound)
205       aState = anIt.key();
206   }
207   if (aFound)
208     emit showConstraintToggled(aState, theOn);
209 }
210
211 void PartSet_WidgetSketchLabel::blockAttribute(const AttributePtr& theAttribute,
212                                                const bool& theToBlock, bool& isFlushesActived,
213                                                bool& isAttributeSetInitializedBlocked)
214 {
215   ModuleBase_WidgetValidated::blockAttribute(theAttribute, theToBlock, isFlushesActived,
216                                              isAttributeSetInitializedBlocked);
217   // We do not restore the previous state of isAttributeSetInitializedBlocked for each of
218   // attributes. It it is necessary, these states should be append to the method attributes
219   // or stored in the widget
220
221   std::list<AttributePtr> anAttributes = myFeature->data()->attributes("");
222   std::list<AttributePtr>::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end();
223   QStringList aValues;
224   for(; anIt != aLast; anIt++) {
225     AttributePtr anAttribute = *anIt;
226     if (theToBlock)
227       anAttribute->blockSetInitialized(true);
228     else
229       anAttribute->blockSetInitialized(isAttributeSetInitializedBlocked);
230   }
231 }
232
233 bool PartSet_WidgetSketchLabel::setSelectionInternal(
234                                           const QList<ModuleBase_ViewerPrsPtr>& theValues,
235                                           const bool theToValidate)
236 {
237   bool aDone = false;
238   if (theValues.empty()) {
239     // In order to make reselection possible, set empty object and shape should be done
240     setSelectionCustom(std::shared_ptr<ModuleBase_ViewerPrs>(
241                               new ModuleBase_ViewerPrs(ObjectPtr(), GeomShapePtr(), NULL)));
242     aDone = false;
243   }
244   else {
245     // it removes the processed value from the parameters list
246     ModuleBase_ViewerPrsPtr aValue = theValues.first();//.takeFirst();
247     if (!theToValidate || isValidInFilters(aValue))
248       aDone = setSelectionCustom(aValue);
249   }
250
251   return aDone;
252 }
253
254 void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrsPtr& thePrs)
255 {
256   // 1. hide main planes if they have been displayed
257   myPreviewPlanes->erasePreviewPlanes(myWorkshop);
258   // 2. if the planes were displayed, change the view projection
259   const GeomShapePtr& aShape = thePrs->shape();
260   std::shared_ptr<GeomAPI_Shape> aGShape;
261   std::shared_ptr<GeomAPI_Shape> aBaseShape;
262
263   DataPtr aData = feature()->data();
264   AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
265                             (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
266
267   // selection happens in OCC viewer
268   if (aShape.get() && !aShape->isNull()) {
269     aGShape = aShape;
270
271     if (aSelAttr && aSelAttr->context()) {
272       aBaseShape = aSelAttr->context()->shape();
273     }
274   }
275   else { // selection happens in OCC viewer(on body) of in the OB browser
276     if (aSelAttr) {
277       aGShape = aSelAttr->value();
278     }
279   }
280   if (aGShape.get() != NULL) {
281     // get plane parameters
282     std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aGShape));
283     std::shared_ptr<GeomAPI_Pln> aPlane = aFace->getPlane();
284     std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
285     gp_XYZ aXYZ = aDir->impl<gp_Dir>().XYZ();
286     double aTwist = 0.0;
287
288     // orienting projection is not needed: it is done in GeomAlgoAPI_FaceBuilder::plane
289     /*if (aGShape->impl<TopoDS_Shape>().Orientation() == TopAbs_REVERSED) {
290       aXYZ.Reverse();
291     }*/
292
293     // Rotate view if the sketcher plane is selected only from preview planes
294     // Preview planes are created only if there is no any shape
295     bool aRotate = Config_PropManager::boolean(SKETCH_TAB_NAME, "rotate_to_plane", "false");
296     if (aRotate) {
297       myWorkshop->viewer()->setViewProjection(aXYZ.X(), aXYZ.Y(), aXYZ.Z(), aTwist);
298       PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
299       if (aModule)
300         aModule->onViewTransformed();
301     }
302     QString aSizeOfViewStr = mySizeOfView->text();
303     if (!aSizeOfViewStr.isEmpty()) {
304       bool isOk;
305       double aSizeOfView = aSizeOfViewStr.toDouble(&isOk);
306       if (isOk && aSizeOfView > 0) {
307         Handle(V3d_View) aView3d = myWorkshop->viewer()->activeView();
308         if (!aView3d.IsNull()) {
309           Bnd_Box aBndBox;
310           double aHalfSize = aSizeOfView/2.0;
311           aBndBox.Update(-aHalfSize, -aHalfSize, -aHalfSize, aHalfSize, aHalfSize, aHalfSize);
312           aView3d->FitAll(aBndBox, 0.01, false);
313         }
314       }
315     }
316   }
317   // 3. Clear text in the label
318   myStackWidget->setCurrentIndex(1);
319   //myLabel->setText("");
320   //myLabel->setToolTip("");
321   XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
322   disconnect(aWorkshop->selector(), SIGNAL(selectionChanged()),
323               this, SLOT(onSelectionChanged()));
324   // 4. deactivate face selection filter
325   activateFilters(false);
326
327   // 5. Clear selection mode and define sketching mode
328   //XGUI_Displayer* aDisp = aWorkshop->displayer();
329   //aDisp->closeLocalContexts();
330   emit planeSelected(plane());
331   // after the plane is selected in the sketch, the sketch selection should be activated
332   // it can not be performed in the sketch label widget because, we don't need to switch off
333   // the selection by any label deactivation, but need to switch it off by stop the sketch
334   activateSelection(true);
335
336   // 6. Update sketcher actions
337   XGUI_ActionsMgr* anActMgr = aWorkshop->actionsMgr();
338   myWorkshop->updateCommandStatus();
339   myWorkshop->viewer()->update();
340 }
341
342 std::shared_ptr<GeomAPI_Pln> PartSet_WidgetSketchLabel::plane() const
343 {
344   CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
345   return PartSet_Tools::sketchPlane(aSketch);
346 }
347
348 bool PartSet_WidgetSketchLabel::focusTo()
349 {
350   ModuleBase_Tools::setFocus(myStackWidget, "PartSet_WidgetSketchLabel::focusTo()");
351   return true;
352 }
353
354 void PartSet_WidgetSketchLabel::enableFocusProcessing()
355 {
356   myStackWidget->installEventFilter(this);
357 }
358
359 void PartSet_WidgetSketchLabel::storeAttributeValue(const AttributePtr& theAttribute)
360 {
361   ModuleBase_WidgetValidated::storeAttributeValue(theAttribute);
362 }
363
364 void PartSet_WidgetSketchLabel::restoreAttributeValue(const AttributePtr& theAttribute,
365                                                       const bool theValid)
366 {
367   ModuleBase_WidgetValidated::restoreAttributeValue(theAttribute, theValid);
368
369   // it is not necessary to save the previous plane value because the plane is chosen once
370   DataPtr aData = feature()->data();
371   AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
372     (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
373   if (aSelAttr) {
374     ResultPtr anEmptyResult;
375     GeomShapePtr anEmptyShape;
376     aSelAttr->setValue(anEmptyResult, anEmptyShape);
377   }
378 }
379
380 bool PartSet_WidgetSketchLabel::setSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
381 {
382   return fillSketchPlaneBySelection(feature(), thePrs);
383 }
384
385 bool PartSet_WidgetSketchLabel::canFillSketch(const ModuleBase_ViewerPrsPtr& thePrs)
386 {
387   bool aCanFillSketch = true;
388   // avoid any selection on sketch object
389   ObjectPtr anObject = thePrs->object();
390   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
391   if (aResult.get()) {
392     FeaturePtr aFeature = ModelAPI_Feature::feature(aResult);
393     if (aFeature->getKind() == SketchPlugin_Sketch::ID())
394       aCanFillSketch = false;
395   }
396   // check plane or planar face of any non-sketch object
397   if (aCanFillSketch) {
398     std::shared_ptr<GeomAPI_Face> aGeomFace;
399
400     GeomShapePtr aGeomShape = thePrs->shape();
401     if ((!aGeomShape.get() || aGeomShape->isNull()) && aResult.get()) {
402       aGeomShape = aResult->shape();
403     }
404
405     if (aGeomShape.get() && aGeomShape->shapeType() == GeomAPI_Shape::FACE) {
406       std::shared_ptr<GeomAPI_Face> aGeomFace(new GeomAPI_Face(aGeomShape));
407       aCanFillSketch = aGeomFace.get() && aGeomFace->isPlanar();
408     }
409     else
410       aCanFillSketch = false;
411   }
412   return aCanFillSketch;
413 }
414
415 bool PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(const FeaturePtr& theFeature,
416                                                            const ModuleBase_ViewerPrsPtr& thePrs)
417 {
418   bool isOwnerSet = false;
419
420   const GeomShapePtr& aShape = thePrs->shape();
421   std::shared_ptr<GeomAPI_Dir> aDir;
422
423   if (thePrs->object() && (theFeature != thePrs->object())) {
424     DataPtr aData = theFeature->data();
425     AttributeSelectionPtr aSelAttr =
426       std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
427       (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
428     if (aSelAttr) {
429       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePrs->object());
430       if (aRes) {
431         GeomShapePtr aShapePtr(new GeomAPI_Shape());
432         if (!aShape.get() || aShape->isNull()) {  // selection happens in the OCC viewer
433           aShapePtr = ModelAPI_Tools::shape(aRes);
434         }
435         else { // selection happens in OB browser
436           aShapePtr = aShape;
437         }
438         if (aShapePtr.get() != NULL) {
439           aSelAttr->setValue(aRes, aShapePtr);
440           isOwnerSet = true;
441         }
442       }
443     }
444   }
445   else if (aShape.get() && !aShape->isNull()) {
446     const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
447     aDir = setSketchPlane(theFeature, aTDShape);
448     isOwnerSet = aDir.get();
449   }
450   return isOwnerSet;
451 }
452
453 void PartSet_WidgetSketchLabel::activateCustom()
454 {
455   std::shared_ptr<GeomAPI_Pln> aPlane = plane();
456   if (aPlane.get()) {
457     myStackWidget->setCurrentIndex(1);
458     activateSelection(true);
459     return;
460   }
461
462   myStackWidget->setCurrentIndex(0);
463   bool aBodyIsVisualized = myPreviewPlanes->hasVisualizedBodies(myWorkshop);
464
465   // Clear previous selection mode It is necessary for correct activation of preview planes
466   XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
467   XGUI_Displayer* aDisp = aWorkshop->displayer();
468   aDisp->activateObjects(QIntList(), aDisp->displayedObjects(), false);
469
470   if (!aBodyIsVisualized) {
471     // We have to select a plane before any operation
472     myPreviewPlanes->showPreviewPlanes(myWorkshop);
473     mySizeOfViewWidget->setVisible(true);
474   }
475   else
476     mySizeOfViewWidget->setVisible(false);
477
478   activateSelection(true);
479
480   //myLabel->setText(myText);
481   //myLabel->setToolTip(myTooltip);
482
483   connect(XGUI_Tools::workshop(myWorkshop)->selector(), SIGNAL(selectionChanged()),
484           this, SLOT(onSelectionChanged()));
485   activateFilters(true);
486 }
487
488 void PartSet_WidgetSketchLabel::deactivate()
489 {
490   ModuleBase_ModelWidget::deactivate();
491   bool aHidePreview = myPreviewPlanes->isPreviewDisplayed();
492   myPreviewPlanes->erasePreviewPlanes(myWorkshop);
493   activateSelection(false);
494
495   activateFilters(false);
496   if (aHidePreview)
497     myWorkshop->viewer()->update();
498 }
499
500 void PartSet_WidgetSketchLabel::activateSelection(bool toActivate)
501 {
502   if (toActivate) {
503     QIntList aModes;
504     std::shared_ptr<GeomAPI_Pln> aPlane = plane();
505     if (aPlane.get()) {
506       myWorkshop->module()->activeSelectionModes(aModes);
507     }
508     else {
509       aModes << TopAbs_FACE;
510     }
511     myWorkshop->activateSubShapesSelection(aModes);
512   } else {
513     myWorkshop->deactivateSubShapesSelection();
514   }
515 }
516
517
518 std::shared_ptr<GeomAPI_Dir> PartSet_WidgetSketchLabel::setSketchPlane(const FeaturePtr& theFeature,
519                                                                        const TopoDS_Shape& theShape)
520 {
521   if (theShape.IsNull())
522     return std::shared_ptr<GeomAPI_Dir>();
523
524   // get selected shape
525   std::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
526   aGShape->setImpl(new TopoDS_Shape(theShape));
527
528
529
530   // get plane parameters
531   std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aGShape));
532   std::shared_ptr<GeomAPI_Pln> aPlane = aFace->getPlane();
533   if (!aPlane.get())
534     return std::shared_ptr<GeomAPI_Dir>();
535
536   // set plane parameters to feature
537   std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
538   double anA, aB, aC, aD;
539   aPlane->coefficients(anA, aB, aC, aD);
540
541   // calculate attributes of the sketch
542   std::shared_ptr<GeomAPI_Dir> aNormDir(new GeomAPI_Dir(anA, aB, aC));
543   std::shared_ptr<GeomAPI_XYZ> aCoords = aNormDir->xyz();
544   std::shared_ptr<GeomAPI_XYZ> aZero(new GeomAPI_XYZ(0, 0, 0));
545   aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero));
546   std::shared_ptr<GeomAPI_Pnt> anOrigPnt(new GeomAPI_Pnt(aCoords));
547   // X axis is preferable to be dirX on the sketch
548   const double tol = Precision::Confusion();
549   bool isX = fabs(anA - 1.0) < tol && fabs(aB) < tol && fabs(aC) < tol;
550   std::shared_ptr<GeomAPI_Dir> aTempDir(
551       isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0));
552   std::shared_ptr<GeomAPI_Dir> aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir)));
553   std::shared_ptr<GeomAPI_Dir> aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir)));
554
555   std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
556       aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
557   anOrigin->setValue(anOrigPnt);
558   std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
559       aData->attribute(SketchPlugin_Sketch::NORM_ID()));
560   aNormal->setValue(aNormDir);
561   std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
562       aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
563   aDirX->setValue(aXDir);
564   std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
565   return aDir;
566 }
567
568 void PartSet_WidgetSketchLabel::onSetPlaneView()
569 {
570   std::shared_ptr<GeomAPI_Pln> aPlane = plane();
571   if (aPlane.get()) {
572     std::shared_ptr<GeomAPI_Dir> aDirection = aPlane->direction();
573     gp_Dir aDir = aDirection->impl<gp_Dir>();
574     if (myViewInverted->isChecked())
575       aDir.Reverse();
576     myWorkshop->viewer()->setViewProjection(aDir.X(), aDir.Y(), aDir.Z(), 0.);
577     PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
578     if (aModule)
579       aModule->onViewTransformed();
580   }
581 }