1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "PartSet_WidgetSketchLabel.h"
21 #include "PartSet_Tools.h"
22 #include "PartSet_Module.h"
23 #include "PartSet_PreviewPlanes.h"
25 #include "SketchPlugin_SketchEntity.h"
27 #include <XGUI_ActionsMgr.h>
28 #include <XGUI_Displayer.h>
29 #include <XGUI_ModuleConnector.h>
30 #include <XGUI_SelectionActivate.h>
31 #include <XGUI_Selection.h>
32 #include <XGUI_SelectionMgr.h>
33 #include <XGUI_Tools.h>
34 #include <XGUI_ViewerProxy.h>
35 #include <XGUI_Workshop.h>
37 #include <ModelAPI_ResultBody.h>
38 #include <ModelAPI_Tools.h>
40 #include <ModuleBase_Operation.h>
41 #include <ModuleBase_ViewerPrs.h>
42 #include <ModuleBase_Tools.h>
43 #include <ModuleBase_IModule.h>
44 #include <ModuleBase_IPropertyPanel.h>
46 #include <GeomAlgoAPI_FaceBuilder.h>
47 #include <GeomAlgoAPI_ShapeTools.h>
48 #include <GeomDataAPI_Point.h>
49 #include <GeomDataAPI_Dir.h>
50 #include <GeomAPI_XYZ.h>
51 #include <GeomAPI_Face.h>
52 #include <GeomAPI_Edge.h>
53 #include <GeomAPI_ShapeExplorer.h>
55 #include <SketchPlugin_Sketch.h>
56 #include <SketcherPrs_Tools.h>
58 #include <Precision.hxx>
62 #include <AIS_Shape.hxx>
63 #include <AIS_DimensionSelectionMode.hxx>
64 #include <Bnd_Box.hxx>
66 #include <Config_WidgetAPI.h>
67 #include <Config_PropManager.h>
70 #include <QApplication>
71 #include <QVBoxLayout>
72 #include <QHBoxLayout>
75 #include <QPushButton>
76 #include <QStackedWidget>
78 #include <QDoubleValidator>
81 #define DBL_MAX 1.7976931348623158e+308
84 PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent,
85 ModuleBase_IWorkshop* theWorkshop,
86 const Config_WidgetAPI* theData,
87 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& toShowConstraints)
88 : ModuleBase_WidgetValidated(theParent, theWorkshop, theData), myOpenTransaction(false),
91 QVBoxLayout* aLayout = new QVBoxLayout(this);
92 ModuleBase_Tools::zeroMargins(aLayout);
94 myStackWidget = new QStackedWidget(this);
95 myStackWidget->setContentsMargins(0,0,0,0);
96 aLayout->addWidget(myStackWidget);
98 // Define label for plane selection
99 QWidget* aFirstWgt = new QWidget(this);
101 // Size of the View control
102 mySizeOfViewWidget = new QWidget(aFirstWgt);
103 QHBoxLayout* aSizeLayout = new QHBoxLayout(mySizeOfViewWidget);
104 aSizeLayout->addWidget(new QLabel("Size of the view", mySizeOfViewWidget));
105 mySizeOfView = new QLineEdit(mySizeOfViewWidget);
107 QDoubleValidator* aValidator = new QDoubleValidator(0, DBL_MAX, 12, mySizeOfView);
108 aValidator->setLocale(ModuleBase_Tools::doubleLocale());
109 aValidator->setNotation(QDoubleValidator::StandardNotation);
110 mySizeOfView->setValidator(aValidator);
111 aSizeLayout->addWidget(mySizeOfView);
113 QString aText = QString::fromStdString(theData->getProperty("title"));
114 QLabel* aLabel = new QLabel(aText, aFirstWgt);
115 aLabel->setWordWrap(true);
116 QString aTooltip = QString::fromStdString(theData->getProperty("tooltip"));
117 aLabel->setToolTip(aTooltip);
118 aLabel->setIndent(5);
120 aLayout = new QVBoxLayout(aFirstWgt);
121 ModuleBase_Tools::zeroMargins(aLayout);
122 aLayout->addWidget(mySizeOfViewWidget);
123 aLayout->addWidget(aLabel);
125 myRemoveExternal = new QCheckBox(tr("Remove external dependencies"), aFirstWgt);
126 myRemoveExternal->setChecked(false);
127 aLayout->addWidget(myRemoveExternal);
128 myRemoveExternal->setVisible(false);
130 aLayout->addStretch(1);
132 myStackWidget->addWidget(aFirstWgt);
134 // Define widget for sketch manmagement
135 QWidget* aSecondWgt = new QWidget(this);
136 aLayout = new QVBoxLayout(aSecondWgt);
137 ModuleBase_Tools::zeroMargins(aLayout);
139 QGroupBox* aViewBox = new QGroupBox(tr("Sketcher plane"), this);
140 QVBoxLayout* aViewLayout = new QVBoxLayout(aViewBox);
142 myViewInverted = new QCheckBox(tr("Reversed"), aViewBox);
143 aViewLayout->addWidget(myViewInverted);
145 QPushButton* aSetViewBtn =
146 new QPushButton(QIcon(":icons/plane_view.png"), tr("Set plane view"), aViewBox);
147 connect(aSetViewBtn, SIGNAL(clicked(bool)), this, SLOT(onSetPlaneView()));
148 aViewLayout->addWidget(aSetViewBtn);
150 aLayout->addWidget(aViewBox);
152 QMap<PartSet_Tools::ConstraintVisibleState, QString> aStates;
153 aStates[PartSet_Tools::Geometrical] = tr("Show geometrical constraints");
154 aStates[PartSet_Tools::Dimensional] = tr("Show dimensional constraints");
155 aStates[PartSet_Tools::Expressions] = tr("Show existing expressions");
157 QMap<PartSet_Tools::ConstraintVisibleState, QString>::const_iterator anIt = aStates.begin(),
158 aLast = aStates.end();
159 for (; anIt != aLast; anIt++) {
160 QCheckBox* aShowConstraints = new QCheckBox(anIt.value(), this);
161 connect(aShowConstraints, SIGNAL(toggled(bool)), this, SLOT(onShowConstraint(bool)));
162 aLayout->addWidget(aShowConstraints);
164 PartSet_Tools::ConstraintVisibleState aState = anIt.key();
165 myShowConstraints[aState] = aShowConstraints;
167 if (toShowConstraints.contains(aState))
168 aShowConstraints->setChecked(toShowConstraints[aState]);
170 myShowPoints = new QCheckBox(tr("Show free points"), this);
171 connect(myShowPoints, SIGNAL(toggled(bool)), this, SIGNAL(showFreePoints(bool)));
172 aLayout->addWidget(myShowPoints);
174 QPushButton* aPlaneBtn = new QPushButton(tr("Change sketch plane"), aSecondWgt);
175 connect(aPlaneBtn, SIGNAL(clicked(bool)), SLOT(onChangePlane()));
176 aLayout->addWidget(aPlaneBtn);
178 myStackWidget->addWidget(aSecondWgt);
179 //setLayout(aLayout);
181 myPreviewPlanes = new PartSet_PreviewPlanes();
184 PartSet_WidgetSketchLabel::~PartSet_WidgetSketchLabel()
188 bool PartSet_WidgetSketchLabel::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValues,
189 const bool theToValidate)
191 // do not use the given selection if the plane of the sketch has been already set.
192 // If this check is absent, a selected plane in the viewer can be set in the sketch
193 // even if the sketch is built on another plane.
197 ModuleBase_ViewerPrsPtr aPrs = theValues.first();
198 bool aDone = setSelectionInternal(theValues, theToValidate);
200 updateByPlaneSelected(aPrs);
204 QList<QWidget*> PartSet_WidgetSketchLabel::getControls() const
206 QList<QWidget*> aResult;
207 aResult << myStackWidget;
211 bool PartSet_WidgetSketchLabel::processSelection()
213 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
217 QList<ModuleBase_ViewerPrsPtr> aSelected = getFilteredSelected();
219 if (aSelected.empty())
221 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
222 bool aDone = setSelectionInternal(aSelected, false);
224 updateByPlaneSelected(aPrs);
225 updateObject(myFeature);
231 void PartSet_WidgetSketchLabel::onShowConstraint(bool theOn)
233 QCheckBox* aSenderCheckBox = qobject_cast<QCheckBox*>(sender());
235 QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*>::const_iterator
236 anIt = myShowConstraints.begin(), aLast = myShowConstraints.end();
238 PartSet_Tools::ConstraintVisibleState aState = PartSet_Tools::Geometrical;
240 for (; anIt != aLast && !aFound; anIt++) {
241 aFound = anIt.value() == aSenderCheckBox;
246 emit showConstraintToggled(aState, theOn);
249 void PartSet_WidgetSketchLabel::blockAttribute(const AttributePtr& theAttribute,
250 const bool& theToBlock, bool& isFlushesActived,
251 bool& isAttributeSetInitializedBlocked,
252 bool& isAttributeSendUpdatedBlocked)
254 ModuleBase_WidgetValidated::blockAttribute(theAttribute, theToBlock, isFlushesActived,
255 isAttributeSetInitializedBlocked,
256 isAttributeSendUpdatedBlocked);
257 // We do not restore the previous state of isAttributeSetInitializedBlocked for each of
258 // attributes. It it is necessary, these states should be append to the method attributes
259 // or stored in the widget
261 std::list<AttributePtr> anAttributes = myFeature->data()->attributes("");
262 std::list<AttributePtr>::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end();
264 for(; anIt != aLast; anIt++) {
265 AttributePtr anAttribute = *anIt;
267 anAttribute->blockSetInitialized(true);
269 anAttribute->blockSetInitialized(isAttributeSetInitializedBlocked);
273 bool PartSet_WidgetSketchLabel::setSelectionInternal(
274 const QList<ModuleBase_ViewerPrsPtr>& theValues,
275 const bool theToValidate)
278 if (theValues.empty()) {
279 // In order to make reselection possible, set empty object and shape should be done
280 setSelectionCustom(std::shared_ptr<ModuleBase_ViewerPrs>(
281 new ModuleBase_ViewerPrs(ObjectPtr(), GeomShapePtr(), NULL)));
285 // it removes the processed value from the parameters list
286 ModuleBase_ViewerPrsPtr aValue = theValues.first();//.takeFirst();
287 if (!theToValidate || isValidInFilters(aValue)) {
288 myIsSelection = true;
289 aDone = setSelectionCustom(aValue);
290 myIsSelection = false;
297 void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrsPtr& thePrs)
299 GeomPlanePtr aPlane = plane();
302 // 1. hide main planes if they have been displayed and display sketch preview plane
303 myPreviewPlanes->erasePreviewPlanes(myWorkshop);
305 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
307 CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
308 bool isSetSizeOfView = false;
309 double aSizeOfView = 0;
310 QString aSizeOfViewStr = mySizeOfView->text();
311 if (!aSizeOfViewStr.isEmpty()) {
312 aSizeOfView = aSizeOfViewStr.toDouble(&isSetSizeOfView);
313 if (isSetSizeOfView && aSizeOfView <= 0) {
314 isSetSizeOfView = false;
318 aModule->sketchMgr()->previewSketchPlane()->setSizeOfView(aSizeOfView, true);
319 aModule->sketchMgr()->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
321 aModule->sketchMgr()->previewSketchPlane()->setSizeOfView(aSizeOfView, false);
323 // 2. if the planes were displayed, change the view projection
325 std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
326 gp_XYZ aXYZ = aDir->impl<gp_Dir>().XYZ();
329 // Rotate view if the sketcher plane is selected only from preview planes
330 // Preview planes are created only if there is no any shape
331 bool aRotate = Config_PropManager::boolean(SKETCH_TAB_NAME, "rotate_to_plane");
333 myWorkshop->viewer()->setViewProjection(aXYZ.X(), aXYZ.Y(), aXYZ.Z(), aTwist);
335 QString aSizeOfViewStr = mySizeOfView->text();
336 if (!aSizeOfViewStr.isEmpty()) {
338 double aSizeOfView = aSizeOfViewStr.toDouble(&isOk);
339 if (isOk && aSizeOfView > 0) {
340 Handle(V3d_View) aView3d = myWorkshop->viewer()->activeView();
341 if (!aView3d.IsNull()) {
343 double aHalfSize = aSizeOfView/2.0;
344 aBndBox.Update(-aHalfSize, -aHalfSize, -aHalfSize, aHalfSize, aHalfSize, aHalfSize);
345 aView3d->FitAll(aBndBox, 0.01, false);
349 if (myOpenTransaction) {
350 SessionPtr aMgr = ModelAPI_Session::get();
351 aMgr->finishOperation();
352 myOpenTransaction = false;
354 // 3. Clear text in the label
355 myStackWidget->setCurrentIndex(1);
356 //myLabel->setText("");
357 //myLabel->setToolTip("");
358 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
360 // 5. Clear selection mode and define sketching mode
361 emit planeSelected(plane());
362 // after the plane is selected in the sketch, the sketch selection should be activated
363 // it can not be performed in the sketch label widget because, we don't need to switch off
364 // the selection by any label deactivation, but need to switch it off by stop the sketch
365 myWorkshop->selectionActivate()->updateSelectionFilters();
366 myWorkshop->selectionActivate()->updateSelectionModes();
369 aModule->onViewTransformed();
371 // 6. Update sketcher actions
372 XGUI_ActionsMgr* anActMgr = aWorkshop->actionsMgr();
374 myWorkshop->updateCommandStatus();
375 aWorkshop->selector()->clearSelection();
376 myWorkshop->viewer()->update();
378 myRemoveExternal->setVisible(false);
381 std::shared_ptr<GeomAPI_Pln> PartSet_WidgetSketchLabel::plane() const
383 CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
384 return PartSet_Tools::sketchPlane(aSketch);
387 bool PartSet_WidgetSketchLabel::focusTo()
389 ModuleBase_Tools::setFocus(myStackWidget, "PartSet_WidgetSketchLabel::focusTo()");
393 void PartSet_WidgetSketchLabel::enableFocusProcessing()
395 myStackWidget->installEventFilter(this);
398 void PartSet_WidgetSketchLabel::storeAttributeValue(const AttributePtr& theAttribute)
400 ModuleBase_WidgetValidated::storeAttributeValue(theAttribute);
403 void PartSet_WidgetSketchLabel::restoreAttributeValue(const AttributePtr& theAttribute,
406 ModuleBase_WidgetValidated::restoreAttributeValue(theAttribute, theValid);
408 // it is not necessary to save the previous plane value because the plane is chosen once
409 DataPtr aData = feature()->data();
410 AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
411 (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
413 ResultPtr anEmptyResult;
414 GeomShapePtr anEmptyShape;
415 aSelAttr->setValue(anEmptyResult, anEmptyShape);
419 bool PartSet_WidgetSketchLabel::setSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
421 if (myIsSelection && myRemoveExternal->isVisible()) {
422 if (myRemoveExternal->isChecked()) {
423 myFeature->customAction(SketchPlugin_Sketch::ACTION_REMOVE_EXTERNAL());
426 return fillSketchPlaneBySelection(thePrs);
429 bool PartSet_WidgetSketchLabel::canFillSketch(const ModuleBase_ViewerPrsPtr& thePrs)
431 bool aCanFillSketch = true;
432 // avoid any selection on sketch object
433 ObjectPtr anObject = thePrs->object();
434 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
436 FeaturePtr aFeature = ModelAPI_Feature::feature(aResult);
437 if (aFeature->getKind() == SketchPlugin_Sketch::ID())
438 aCanFillSketch = false;
440 // check plane or planar face of any non-sketch object
441 if (aCanFillSketch) {
442 std::shared_ptr<GeomAPI_Face> aGeomFace;
444 GeomShapePtr aGeomShape = thePrs->shape();
445 if ((!aGeomShape.get() || aGeomShape->isNull()) && aResult.get()) {
446 aGeomShape = aResult->shape();
449 if (aGeomShape.get() && aGeomShape->shapeType() == GeomAPI_Shape::FACE) {
450 std::shared_ptr<GeomAPI_Face> aGeomFace(new GeomAPI_Face(aGeomShape));
451 aCanFillSketch = aGeomFace.get() && aGeomFace->isPlanar();
454 aCanFillSketch = false;
456 return aCanFillSketch;
459 bool PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(const ModuleBase_ViewerPrsPtr& thePrs)
461 bool isOwnerSet = false;
463 const GeomShapePtr& aShape = thePrs->shape();
464 std::shared_ptr<GeomAPI_Dir> aDir;
466 if (aShape.get() && !aShape->isNull()) {
467 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
468 aDir = setSketchPlane(aTDShape);
469 isOwnerSet = aDir.get();
471 if (thePrs->object() && (feature() != thePrs->object())) {
472 FeaturePtr aFeature = ModelAPI_Feature::feature(thePrs->object());
473 DataPtr aData = feature()->data();
474 AttributeSelectionPtr aSelAttr =
475 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
476 (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
477 if (aSelAttr.get()) {
478 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePrs->object());
480 GeomShapePtr aShapePtr;
481 if (!aShape.get() || aShape->isNull()) { // selection happens in the OCC viewer
482 aShapePtr = ModelAPI_Tools::shape(aRes);
484 else { // selection happens in OB browser
487 if (aShapePtr.get() && aShapePtr->isFace()) {
488 const TopoDS_Shape& aTDShape = aShapePtr->impl<TopoDS_Shape>();
489 setSketchPlane(aTDShape);
490 aSelAttr->setValue(aRes, aShapePtr);
495 aSelAttr->setValue(aFeature, GeomShapePtr());
496 GeomShapePtr aShape = aSelAttr->value();
497 if (!aShape.get() && aSelAttr->contextFeature().get() &&
498 aSelAttr->contextFeature()->firstResult().get()) {
499 aShape = aSelAttr->contextFeature()->firstResult()->shape();
501 if (aShape.get() && aShape->isPlanar()) {
502 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
503 setSketchPlane(aTDShape);
512 void PartSet_WidgetSketchLabel::activateCustom()
514 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
516 myStackWidget->setCurrentIndex(1);
520 myStackWidget->setCurrentIndex(0);
521 bool aBodyIsVisualized = myPreviewPlanes->hasVisualizedBodies(myWorkshop);
523 // Clear previous selection mode It is necessary for correct activation of preview planes
524 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
525 XGUI_Displayer* aDisp = aWorkshop->displayer();
526 aWorkshop->selectionActivate()->activateObjects(QIntList(), aDisp->displayedObjects(), false);
528 if (!aBodyIsVisualized) {
529 // We have to select a plane before any operation
530 myPreviewPlanes->showPreviewPlanes(myWorkshop);
531 mySizeOfViewWidget->setVisible(true);
534 mySizeOfViewWidget->setVisible(false);
537 void PartSet_WidgetSketchLabel::deactivate()
539 ModuleBase_WidgetValidated::deactivate();
540 bool aHidePreview = myPreviewPlanes->isPreviewDisplayed();
541 myPreviewPlanes->erasePreviewPlanes(myWorkshop);
544 myWorkshop->viewer()->update();
547 void PartSet_WidgetSketchLabel::selectionModes(int& theModuleSelectionModes, QIntList& theModes)
549 theModuleSelectionModes = -1;
550 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
552 theModes << TopAbs_FACE;
555 void PartSet_WidgetSketchLabel::selectionFilters(QIntList& theModuleSelectionFilters,
556 SelectMgr_ListOfFilter& theSelectionFilters)
558 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
561 return ModuleBase_WidgetValidated::selectionFilters(theModuleSelectionFilters,
562 theSelectionFilters);
565 std::shared_ptr<GeomAPI_Dir>
566 PartSet_WidgetSketchLabel::setSketchPlane(const TopoDS_Shape& theShape)
568 if (theShape.IsNull())
569 return std::shared_ptr<GeomAPI_Dir>();
571 // get selected shape
572 std::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
573 aGShape->setImpl(new TopoDS_Shape(theShape));
575 // get plane parameters
576 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aGShape));
577 std::shared_ptr<GeomAPI_Pln> aPlane = aFace->getPlane();
579 return std::shared_ptr<GeomAPI_Dir>();
580 return setSketchPlane(aPlane);
583 std::shared_ptr<GeomAPI_Dir>
584 PartSet_WidgetSketchLabel::setSketchPlane(std::shared_ptr<GeomAPI_Pln> thePlane)
586 // set plane parameters to feature
587 std::shared_ptr<ModelAPI_Data> aData = feature()->data();
588 double anA, aB, aC, aD;
589 thePlane->coefficients(anA, aB, aC, aD);
591 // calculate attributes of the sketch
592 std::shared_ptr<GeomAPI_Dir> aNormDir(new GeomAPI_Dir(anA, aB, aC));
593 std::shared_ptr<GeomAPI_XYZ> aCoords = aNormDir->xyz();
594 std::shared_ptr<GeomAPI_XYZ> aZero(new GeomAPI_XYZ(0, 0, 0));
595 aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero));
596 std::shared_ptr<GeomAPI_Pnt> anOrigPnt(new GeomAPI_Pnt(aCoords));
597 // X axis is preferable to be dirX on the sketch
598 const double tol = Precision::Confusion();
599 bool isX = fabs(fabs(anA) - 1.0) < tol && fabs(aB) < tol && fabs(aC) < tol;
600 std::shared_ptr<GeomAPI_Dir> aTempDir(
601 isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0));
602 std::shared_ptr<GeomAPI_Dir> aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir)));
603 std::shared_ptr<GeomAPI_Dir> aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir)));
605 std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
606 aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
607 anOrigin->setValue(anOrigPnt);
608 std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
609 aData->attribute(SketchPlugin_Sketch::NORM_ID()));
610 aNormal->setValue(aNormDir);
611 std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
612 aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
613 aDirX->setValue(aXDir);
614 std::shared_ptr<GeomAPI_Dir> aDir = thePlane->direction();
618 void PartSet_WidgetSketchLabel::onSetPlaneView()
620 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
622 std::shared_ptr<GeomAPI_Dir> aDirection = aPlane->direction();
623 gp_Dir aDir = aDirection->impl<gp_Dir>();
624 if (myViewInverted->isChecked())
626 myWorkshop->viewer()->setViewProjection(aDir.X(), aDir.Y(), aDir.Z(), 0.);
627 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
629 aModule->onViewTransformed();
634 //******************************************************
635 QList<std::shared_ptr<ModuleBase_ViewerPrs>> PartSet_WidgetSketchLabel::findCircularEdgesInPlane()
637 QList<std::shared_ptr<ModuleBase_ViewerPrs>> aResult;
638 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
639 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
640 QObjectPtrList aDispObjects = aDisplayer->displayedObjects();
642 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
643 foreach(ObjectPtr aObj, aDispObjects) {
644 ResultPtr aResObj = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
646 GeomShapePtr aShape = aResObj->shape();
648 GeomAPI_ShapeExplorer aExplorer(aShape, GeomAPI_Shape::EDGE);
649 for(; aExplorer.more(); aExplorer.next()) {
650 GeomShapePtr aEdgeShape = aExplorer.current();
651 GeomAPI_Edge anEdge(aEdgeShape);
652 if ((anEdge.isCircle() || anEdge.isArc() || anEdge.isEllipse()) &&
653 anEdge.isInPlane(aPlane)) {
654 bool isContains = false;
655 // Check that edge is not used.
656 // It is possible that the same edge will be taken from different faces
657 foreach(std::shared_ptr<ModuleBase_ViewerPrs> aPrs, aResult) {
658 GeomAPI_Edge aUsedEdge(aPrs->shape());
659 if (aUsedEdge.isEqual(aEdgeShape)) {
665 std::shared_ptr<ModuleBase_ViewerPrs>
666 aPrs(new ModuleBase_ViewerPrs(aResObj, aEdgeShape));
667 aResult.append(aPrs);
677 //******************************************************
678 void PartSet_WidgetSketchLabel::onChangePlane()
680 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
682 mySizeOfViewWidget->setVisible(false);
683 myRemoveExternal->setVisible(true);
684 myStackWidget->setCurrentIndex(0);
686 CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
687 PartSet_Tools::nullifySketchPlane(aSketch);
689 Handle(SelectMgr_Filter) aFilter = aModule->selectionFilter(SF_SketchPlaneFilter);
690 if (!aFilter.IsNull()) {
691 std::shared_ptr<GeomAPI_Pln> aPln;
692 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(aPln);
694 XGUI_Workshop* aWorkshop = aModule->getWorkshop();
696 aWorkshop->selectionActivate()->updateSelectionFilters();
697 aWorkshop->selectionActivate()->updateSelectionModes();
699 SessionPtr aMgr = ModelAPI_Session::get();
700 aMgr->startOperation();
701 myOpenTransaction = true;
705 void PartSet_WidgetSketchLabel::setShowPointsState(bool theState)
707 bool aBlock = myShowPoints->blockSignals(true);
708 myShowPoints->setChecked(theState);
709 myShowPoints->blockSignals(aBlock);