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"
24 #include "PartSet_SketcherReentrantMgr.h"
26 #include "SketchPlugin_SketchEntity.h"
28 #include <XGUI_ActionsMgr.h>
29 #include <XGUI_Displayer.h>
30 #include <XGUI_ModuleConnector.h>
31 #include <XGUI_SelectionActivate.h>
32 #include <XGUI_Selection.h>
33 #include <XGUI_SelectionMgr.h>
34 #include <XGUI_Tools.h>
35 #include <XGUI_ViewerProxy.h>
36 #include <XGUI_Workshop.h>
38 #include <ModelAPI_ResultBody.h>
39 #include <ModelAPI_Tools.h>
40 #include <ModelAPI_AttributeString.h>
41 #include <ModelAPI_Events.h>
43 #include <ModuleBase_Operation.h>
44 #include <ModuleBase_ViewerPrs.h>
45 #include <ModuleBase_Tools.h>
46 #include <ModuleBase_IModule.h>
47 #include <ModuleBase_IPropertyPanel.h>
49 #include <GeomAlgoAPI_FaceBuilder.h>
50 #include <GeomAlgoAPI_ShapeTools.h>
51 #include <GeomDataAPI_Point.h>
52 #include <GeomDataAPI_Dir.h>
53 #include <GeomAPI_XYZ.h>
54 #include <GeomAPI_Face.h>
55 #include <GeomAPI_Edge.h>
56 #include <GeomAPI_ShapeExplorer.h>
58 #include <SketchPlugin_Sketch.h>
59 #include <SketcherPrs_Tools.h>
61 #include <Precision.hxx>
65 #include <AIS_Shape.hxx>
66 #include <AIS_DimensionSelectionMode.hxx>
67 #include <Bnd_Box.hxx>
69 #include <Config_WidgetAPI.h>
70 #include <Config_PropManager.h>
73 #include <QApplication>
74 #include <QVBoxLayout>
75 #include <QHBoxLayout>
78 #include <QPushButton>
79 #include <QStackedWidget>
81 #include <QDoubleValidator>
84 #define DBL_MAX 1.7976931348623158e+308
87 PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent,
88 ModuleBase_IWorkshop* theWorkshop,
89 const Config_WidgetAPI* theData,
90 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& toShowConstraints)
91 : ModuleBase_WidgetValidated(theParent, theWorkshop, theData), myOpenTransaction(false),
94 QVBoxLayout* aLayout = new QVBoxLayout(this);
95 ModuleBase_Tools::zeroMargins(aLayout);
97 myStackWidget = new QStackedWidget(this);
98 myStackWidget->setContentsMargins(0,0,0,0);
99 aLayout->addWidget(myStackWidget);
101 // Define label for plane selection
102 QWidget* aFirstWgt = new QWidget(this);
104 // Size of the View control
105 mySizeOfViewWidget = new QWidget(aFirstWgt);
106 QHBoxLayout* aSizeLayout = new QHBoxLayout(mySizeOfViewWidget);
107 aSizeLayout->addWidget(new QLabel(tr("Size of the view"), mySizeOfViewWidget));
108 mySizeOfView = new QLineEdit(mySizeOfViewWidget);
110 QDoubleValidator* aValidator = new QDoubleValidator(0, DBL_MAX, 12, mySizeOfView);
111 aValidator->setLocale(ModuleBase_Tools::doubleLocale());
112 aValidator->setNotation(QDoubleValidator::StandardNotation);
113 mySizeOfView->setValidator(aValidator);
114 aSizeLayout->addWidget(mySizeOfView);
116 QString aText = translate(theData->getProperty("title"));
117 QLabel* aLabel = new QLabel(aText, aFirstWgt);
118 aLabel->setWordWrap(true);
119 QString aTooltip = translate(theData->getProperty("tooltip"));
120 aLabel->setToolTip(aTooltip);
121 aLabel->setIndent(5);
123 aLayout = new QVBoxLayout(aFirstWgt);
124 ModuleBase_Tools::zeroMargins(aLayout);
125 aLayout->addWidget(mySizeOfViewWidget);
126 aLayout->addWidget(aLabel);
128 myRemoveExternal = new QCheckBox(tr("Remove external dependencies"), aFirstWgt);
129 myRemoveExternal->setChecked(false);
130 aLayout->addWidget(myRemoveExternal);
131 myRemoveExternal->setVisible(false);
133 aLayout->addStretch(1);
135 myStackWidget->addWidget(aFirstWgt);
137 // Define widget for sketch manmagement
138 QWidget* aSecondWgt = new QWidget(this);
139 aLayout = new QVBoxLayout(aSecondWgt);
140 ModuleBase_Tools::zeroMargins(aLayout);
142 QGroupBox* aViewBox = new QGroupBox(tr("Sketcher plane"), this);
143 QVBoxLayout* aViewLayout = new QVBoxLayout(aViewBox);
145 myViewInverted = new QCheckBox(tr("Reversed"), aViewBox);
146 aViewLayout->addWidget(myViewInverted);
148 QPushButton* aSetViewBtn =
149 new QPushButton(QIcon(":icons/plane_view.png"), tr("Set plane view"), aViewBox);
150 connect(aSetViewBtn, SIGNAL(clicked(bool)), this, SLOT(onSetPlaneView()));
151 aViewLayout->addWidget(aSetViewBtn);
153 aLayout->addWidget(aViewBox);
155 QMap<PartSet_Tools::ConstraintVisibleState, QString> aStates;
156 aStates[PartSet_Tools::Geometrical] = tr("Show geometrical constraints");
157 aStates[PartSet_Tools::Dimensional] = tr("Show dimensional constraints");
158 aStates[PartSet_Tools::Expressions] = tr("Show existing expressions");
160 QMap<PartSet_Tools::ConstraintVisibleState, QString>::const_iterator anIt = aStates.begin(),
161 aLast = aStates.end();
162 for (; anIt != aLast; anIt++) {
163 QCheckBox* aShowConstraints = new QCheckBox(anIt.value(), this);
164 connect(aShowConstraints, SIGNAL(toggled(bool)), this, SLOT(onShowConstraint(bool)));
165 aLayout->addWidget(aShowConstraints);
167 PartSet_Tools::ConstraintVisibleState aState = anIt.key();
168 myShowConstraints[aState] = aShowConstraints;
170 if (toShowConstraints.contains(aState))
171 aShowConstraints->setChecked(toShowConstraints[aState]);
173 myShowPoints = new QCheckBox(tr("Show free points"), this);
174 connect(myShowPoints, SIGNAL(toggled(bool)), this, SIGNAL(showFreePoints(bool)));
175 aLayout->addWidget(myShowPoints);
177 myAutoConstraints = new QCheckBox(tr("Automatic constraints"), this);
178 myAutoConstraints->setToolTip(tr("Automatic vertical and horizontal constraints"));
179 connect(myAutoConstraints, SIGNAL(toggled(bool)), this, SIGNAL(autoConstraints(bool)));
180 aLayout->addWidget(myAutoConstraints);
182 QPushButton* aPlaneBtn = new QPushButton(tr("Change sketch plane"), aSecondWgt);
183 connect(aPlaneBtn, SIGNAL(clicked(bool)), SLOT(onChangePlane()));
184 aLayout->addWidget(aPlaneBtn);
186 aLayout->addSpacing(15);
188 myDoFLabel = new QLabel("", aSecondWgt);
189 aLayout->addWidget(myDoFLabel);
191 myShowDOFBtn = new QPushButton(tr("Show remaining DoFs"), aSecondWgt);
192 aLayout->addWidget(myShowDOFBtn);
193 myShowDOFBtn->setEnabled(false);
194 connect(myShowDOFBtn, SIGNAL(clicked(bool)), SLOT(onShowDOF()));
196 myStackWidget->addWidget(aSecondWgt);
197 //setLayout(aLayout);
199 myPreviewPlanes = new PartSet_PreviewPlanes();
202 PartSet_WidgetSketchLabel::~PartSet_WidgetSketchLabel()
206 bool PartSet_WidgetSketchLabel::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValues,
207 const bool theToValidate)
209 // do not use the given selection if the plane of the sketch has been already set.
210 // If this check is absent, a selected plane in the viewer can be set in the sketch
211 // even if the sketch is built on another plane.
215 ModuleBase_ViewerPrsPtr aPrs = theValues.first();
216 bool aDone = setSelectionInternal(theValues, theToValidate);
218 updateByPlaneSelected(aPrs);
222 QList<QWidget*> PartSet_WidgetSketchLabel::getControls() const
224 QList<QWidget*> aResult;
225 aResult << myStackWidget;
229 bool PartSet_WidgetSketchLabel::processSelection()
231 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
235 QList<ModuleBase_ViewerPrsPtr> aSelected = getFilteredSelected();
237 if (aSelected.empty())
239 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
240 bool aDone = setSelectionInternal(aSelected, false);
242 updateByPlaneSelected(aPrs);
243 updateObject(myFeature);
249 void PartSet_WidgetSketchLabel::onShowConstraint(bool theOn)
251 QCheckBox* aSenderCheckBox = qobject_cast<QCheckBox*>(sender());
253 QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*>::const_iterator
254 anIt = myShowConstraints.begin(), aLast = myShowConstraints.end();
256 PartSet_Tools::ConstraintVisibleState aState = PartSet_Tools::Geometrical;
258 for (; anIt != aLast && !aFound; anIt++) {
259 aFound = anIt.value() == aSenderCheckBox;
264 emit showConstraintToggled(aState, theOn);
267 void PartSet_WidgetSketchLabel::blockAttribute(const AttributePtr& theAttribute,
268 const bool& theToBlock, bool& isFlushesActived,
269 bool& isAttributeSetInitializedBlocked,
270 bool& isAttributeSendUpdatedBlocked)
272 ModuleBase_WidgetValidated::blockAttribute(theAttribute, theToBlock, isFlushesActived,
273 isAttributeSetInitializedBlocked,
274 isAttributeSendUpdatedBlocked);
275 // We do not restore the previous state of isAttributeSetInitializedBlocked for each of
276 // attributes. It it is necessary, these states should be append to the method attributes
277 // or stored in the widget
279 std::list<AttributePtr> anAttributes = myFeature->data()->attributes("");
280 std::list<AttributePtr>::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end();
282 for(; anIt != aLast; anIt++) {
283 AttributePtr anAttribute = *anIt;
285 anAttribute->blockSetInitialized(true);
287 anAttribute->blockSetInitialized(isAttributeSetInitializedBlocked);
291 bool PartSet_WidgetSketchLabel::setSelectionInternal(
292 const QList<ModuleBase_ViewerPrsPtr>& theValues,
293 const bool theToValidate)
296 if (theValues.empty()) {
297 // In order to make reselection possible, set empty object and shape should be done
298 setSelectionCustom(std::shared_ptr<ModuleBase_ViewerPrs>(
299 new ModuleBase_ViewerPrs(ObjectPtr(), GeomShapePtr(), NULL)));
303 // it removes the processed value from the parameters list
304 ModuleBase_ViewerPrsPtr aValue = theValues.first();//.takeFirst();
305 if (!theToValidate || isValidInFilters(aValue)) {
306 myIsSelection = true;
307 aDone = setSelectionCustom(aValue);
308 myIsSelection = false;
315 void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrsPtr& thePrs)
317 GeomPlanePtr aPlane = plane();
320 // 1. hide main planes if they have been displayed and display sketch preview plane
321 myPreviewPlanes->erasePreviewPlanes(myWorkshop);
323 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
325 CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
326 bool isSetSizeOfView = false;
327 double aSizeOfView = 0;
328 QString aSizeOfViewStr = mySizeOfView->text();
329 if (!aSizeOfViewStr.isEmpty()) {
330 aSizeOfView = aSizeOfViewStr.toDouble(&isSetSizeOfView);
331 if (isSetSizeOfView && aSizeOfView <= 0) {
332 isSetSizeOfView = false;
335 aModule->sketchMgr()->previewSketchPlane()->setSizeOfView(aSizeOfView, isSetSizeOfView);
336 aModule->sketchMgr()->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
338 // 2. if the planes were displayed, change the view projection
340 std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
341 gp_XYZ aXYZ = aDir->impl<gp_Dir>().XYZ();
344 // Rotate view if the sketcher plane is selected only from preview planes
345 // Preview planes are created only if there is no any shape
346 bool aRotate = Config_PropManager::boolean(SKETCH_TAB_NAME, "rotate_to_plane");
348 myWorkshop->viewer()->setViewProjection(aXYZ.X(), aXYZ.Y(), aXYZ.Z(), aTwist);
350 QString aSizeOfViewStr = mySizeOfView->text();
351 if (!aSizeOfViewStr.isEmpty()) {
353 double aSizeOfView = aSizeOfViewStr.toDouble(&isOk);
354 if (isOk && aSizeOfView > 0) {
355 Handle(V3d_View) aView3d = myWorkshop->viewer()->activeView();
356 if (!aView3d.IsNull()) {
358 double aHalfSize = aSizeOfView/2.0;
359 aBndBox.Update(-aHalfSize, -aHalfSize, -aHalfSize, aHalfSize, aHalfSize, aHalfSize);
360 aView3d->FitAll(aBndBox, 0.01, false);
364 if (myOpenTransaction) {
365 SessionPtr aMgr = ModelAPI_Session::get();
366 aMgr->finishOperation();
367 myOpenTransaction = false;
369 // 3. Clear text in the label
370 myStackWidget->setCurrentIndex(1);
371 //myLabel->setText("");
372 //myLabel->setToolTip("");
373 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
375 // 5. Clear selection mode and define sketching mode
376 emit planeSelected(plane());
377 // after the plane is selected in the sketch, the sketch selection should be activated
378 // it can not be performed in the sketch label widget because, we don't need to switch off
379 // the selection by any label deactivation, but need to switch it off by stop the sketch
380 myWorkshop->selectionActivate()->updateSelectionFilters();
381 myWorkshop->selectionActivate()->updateSelectionModes();
384 aModule->onViewTransformed();
386 // 6. Update sketcher actions
387 XGUI_ActionsMgr* anActMgr = aWorkshop->actionsMgr();
389 myWorkshop->updateCommandStatus();
390 aWorkshop->selector()->clearSelection();
391 myWorkshop->viewer()->update();
393 myRemoveExternal->setVisible(false);
396 std::shared_ptr<GeomAPI_Pln> PartSet_WidgetSketchLabel::plane() const
398 CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
399 return PartSet_Tools::sketchPlane(aSketch);
402 bool PartSet_WidgetSketchLabel::focusTo()
404 ModuleBase_Tools::setFocus(myStackWidget, "PartSet_WidgetSketchLabel::focusTo()");
408 void PartSet_WidgetSketchLabel::enableFocusProcessing()
410 myStackWidget->installEventFilter(this);
413 void PartSet_WidgetSketchLabel::storeAttributeValue(const AttributePtr& theAttribute)
415 ModuleBase_WidgetValidated::storeAttributeValue(theAttribute);
418 void PartSet_WidgetSketchLabel::restoreAttributeValue(const AttributePtr& theAttribute,
421 ModuleBase_WidgetValidated::restoreAttributeValue(theAttribute, theValid);
423 // it is not necessary to save the previous plane value because the plane is chosen once
424 DataPtr aData = feature()->data();
425 AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
426 (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
428 ResultPtr anEmptyResult;
429 GeomShapePtr anEmptyShape;
430 aSelAttr->setValue(anEmptyResult, anEmptyShape);
434 bool PartSet_WidgetSketchLabel::setSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
436 if (myIsSelection && myRemoveExternal->isVisible()) {
437 if (myRemoveExternal->isChecked()) {
438 myFeature->customAction(SketchPlugin_Sketch::ACTION_REMOVE_EXTERNAL());
441 return fillSketchPlaneBySelection(thePrs);
444 bool PartSet_WidgetSketchLabel::canFillSketch(const ModuleBase_ViewerPrsPtr& thePrs)
446 bool aCanFillSketch = true;
447 // avoid any selection on sketch object
448 ObjectPtr anObject = thePrs->object();
449 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
451 FeaturePtr aFeature = ModelAPI_Feature::feature(aResult);
452 if (aFeature->getKind() == SketchPlugin_Sketch::ID())
453 aCanFillSketch = false;
455 // check plane or planar face of any non-sketch object
456 if (aCanFillSketch) {
457 std::shared_ptr<GeomAPI_Face> aGeomFace;
459 GeomShapePtr aGeomShape = thePrs->shape();
460 if ((!aGeomShape.get() || aGeomShape->isNull()) && aResult.get()) {
461 aGeomShape = aResult->shape();
464 if (aGeomShape.get() && aGeomShape->shapeType() == GeomAPI_Shape::FACE) {
465 std::shared_ptr<GeomAPI_Face> aGeomFace(new GeomAPI_Face(aGeomShape));
466 aCanFillSketch = aGeomFace.get() && aGeomFace->isPlanar();
469 aCanFillSketch = false;
471 return aCanFillSketch;
474 bool PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(const ModuleBase_ViewerPrsPtr& thePrs)
476 bool isOwnerSet = false;
478 const GeomShapePtr& aShape = thePrs->shape();
479 std::shared_ptr<GeomAPI_Dir> aDir;
481 if (aShape.get() && !aShape->isNull()) {
482 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
483 aDir = setSketchPlane(aTDShape);
484 isOwnerSet = aDir.get();
486 if (thePrs->object() && (feature() != thePrs->object())) {
487 FeaturePtr aFeature = ModelAPI_Feature::feature(thePrs->object());
488 DataPtr aData = feature()->data();
489 AttributeSelectionPtr aSelAttr =
490 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
491 (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
492 if (aSelAttr.get()) {
493 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePrs->object());
495 GeomShapePtr aShapePtr;
496 if (!aShape.get() || aShape->isNull()) { // selection happens in the OCC viewer
497 aShapePtr = ModelAPI_Tools::shape(aRes);
499 else { // selection happens in OB browser
502 if (aShapePtr.get() && aShapePtr->isFace()) {
503 const TopoDS_Shape& aTDShape = aShapePtr->impl<TopoDS_Shape>();
504 setSketchPlane(aTDShape);
505 aSelAttr->setValue(aRes, aShapePtr);
510 aSelAttr->setValue(aFeature, GeomShapePtr());
511 GeomShapePtr aShape = aSelAttr->value();
512 if (!aShape.get() && aSelAttr->contextFeature().get() &&
513 aSelAttr->contextFeature()->firstResult().get()) {
514 aShape = aSelAttr->contextFeature()->firstResult()->shape();
516 if (aShape.get() && aShape->isPlanar()) {
517 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
518 setSketchPlane(aTDShape);
527 void PartSet_WidgetSketchLabel::activateCustom()
529 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
531 bool isBlocked = myAutoConstraints->blockSignals(true);
532 myAutoConstraints->setChecked(aModule->sketchReentranceMgr()->isAutoConstraints());
533 myAutoConstraints->blockSignals(isBlocked);
536 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
538 myStackWidget->setCurrentIndex(1);
542 myStackWidget->setCurrentIndex(0);
543 bool aBodyIsVisualized = myPreviewPlanes->hasVisualizedBodies(myWorkshop);
545 // Clear previous selection mode It is necessary for correct activation of preview planes
546 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
547 XGUI_Displayer* aDisp = aWorkshop->displayer();
548 aWorkshop->selectionActivate()->activateObjects(QIntList(), aDisp->displayedObjects(), false);
550 if (!aBodyIsVisualized) {
551 // We have to select a plane before any operation
552 myPreviewPlanes->showPreviewPlanes(myWorkshop);
553 mySizeOfViewWidget->setVisible(true);
556 mySizeOfViewWidget->setVisible(false);
559 void PartSet_WidgetSketchLabel::deactivate()
561 ModuleBase_WidgetValidated::deactivate();
562 bool aHidePreview = myPreviewPlanes->isPreviewDisplayed();
563 myPreviewPlanes->erasePreviewPlanes(myWorkshop);
566 myWorkshop->viewer()->update();
568 if (myOpenTransaction) {
569 SessionPtr aMgr = ModelAPI_Session::get();
570 aMgr->finishOperation();
571 myOpenTransaction = false;
575 void PartSet_WidgetSketchLabel::selectionModes(int& theModuleSelectionModes, QIntList& theModes)
577 theModuleSelectionModes = -1;
578 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
580 theModes << TopAbs_FACE;
583 void PartSet_WidgetSketchLabel::selectionFilters(QIntList& theModuleSelectionFilters,
584 SelectMgr_ListOfFilter& theSelectionFilters)
586 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
589 return ModuleBase_WidgetValidated::selectionFilters(theModuleSelectionFilters,
590 theSelectionFilters);
593 std::shared_ptr<GeomAPI_Dir>
594 PartSet_WidgetSketchLabel::setSketchPlane(const TopoDS_Shape& theShape)
596 if (theShape.IsNull())
597 return std::shared_ptr<GeomAPI_Dir>();
599 // get selected shape
600 std::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
601 aGShape->setImpl(new TopoDS_Shape(theShape));
603 // get plane parameters
604 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aGShape));
605 std::shared_ptr<GeomAPI_Pln> aPlane = aFace->getPlane();
607 return std::shared_ptr<GeomAPI_Dir>();
608 return setSketchPlane(aPlane);
611 std::shared_ptr<GeomAPI_Dir>
612 PartSet_WidgetSketchLabel::setSketchPlane(std::shared_ptr<GeomAPI_Pln> thePlane)
614 // set plane parameters to feature
615 std::shared_ptr<ModelAPI_Data> aData = feature()->data();
616 double anA, aB, aC, aD;
617 thePlane->coefficients(anA, aB, aC, aD);
619 // calculate attributes of the sketch
620 std::shared_ptr<GeomAPI_Dir> aNormDir(new GeomAPI_Dir(anA, aB, aC));
621 std::shared_ptr<GeomAPI_XYZ> aCoords = aNormDir->xyz();
622 std::shared_ptr<GeomAPI_XYZ> aZero(new GeomAPI_XYZ(0, 0, 0));
623 aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero));
624 std::shared_ptr<GeomAPI_Pnt> anOrigPnt(new GeomAPI_Pnt(aCoords));
625 // X axis is preferable to be dirX on the sketch
626 const double tol = Precision::Confusion();
627 bool isX = fabs(fabs(anA) - 1.0) < tol && fabs(aB) < tol && fabs(aC) < tol;
628 std::shared_ptr<GeomAPI_Dir> aTempDir(
629 isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0));
630 std::shared_ptr<GeomAPI_Dir> aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir)));
631 std::shared_ptr<GeomAPI_Dir> aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir)));
633 std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
634 aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
635 anOrigin->setValue(anOrigPnt);
636 std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
637 aData->attribute(SketchPlugin_Sketch::NORM_ID()));
638 aNormal->setValue(aNormDir);
639 std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
640 aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
641 aDirX->setValue(aXDir);
642 std::shared_ptr<GeomAPI_Dir> aDir = thePlane->direction();
646 void PartSet_WidgetSketchLabel::onSetPlaneView()
648 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
650 std::shared_ptr<GeomAPI_Dir> aDirection = aPlane->direction();
651 gp_Dir aDir = aDirection->impl<gp_Dir>();
652 if (myViewInverted->isChecked())
654 myWorkshop->viewer()->setViewProjection(aDir.X(), aDir.Y(), aDir.Z(), 0.);
655 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
657 aModule->onViewTransformed();
662 //******************************************************
663 QList<std::shared_ptr<ModuleBase_ViewerPrs>> PartSet_WidgetSketchLabel::findCircularEdgesInPlane()
665 QList<std::shared_ptr<ModuleBase_ViewerPrs>> aResult;
666 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
667 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
668 QObjectPtrList aDispObjects = aDisplayer->displayedObjects();
670 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
671 foreach(ObjectPtr aObj, aDispObjects) {
672 ResultPtr aResObj = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
674 GeomShapePtr aShape = aResObj->shape();
676 GeomAPI_ShapeExplorer aExplorer(aShape, GeomAPI_Shape::EDGE);
677 for(; aExplorer.more(); aExplorer.next()) {
678 GeomShapePtr aEdgeShape = aExplorer.current();
679 GeomAPI_Edge anEdge(aEdgeShape);
680 if ((anEdge.isCircle() || anEdge.isArc() || anEdge.isEllipse()) &&
681 anEdge.isInPlane(aPlane)) {
682 bool isContains = false;
683 // Check that edge is not used.
684 // It is possible that the same edge will be taken from different faces
685 foreach(std::shared_ptr<ModuleBase_ViewerPrs> aPrs, aResult) {
686 GeomAPI_Edge aUsedEdge(aPrs->shape());
687 if (aUsedEdge.isEqual(aEdgeShape)) {
693 std::shared_ptr<ModuleBase_ViewerPrs>
694 aPrs(new ModuleBase_ViewerPrs(aResObj, aEdgeShape));
695 aResult.append(aPrs);
705 //******************************************************
706 void PartSet_WidgetSketchLabel::onChangePlane()
708 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
710 mySizeOfViewWidget->setVisible(false);
711 myRemoveExternal->setVisible(true);
712 myStackWidget->setCurrentIndex(0);
714 bool aBodyIsVisualized = myPreviewPlanes->hasVisualizedBodies(myWorkshop);
716 if (!aBodyIsVisualized) {
717 // We have to select a plane before any operation
718 myPreviewPlanes->showPreviewPlanes(myWorkshop);
721 CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
722 PartSet_Tools::nullifySketchPlane(aSketch);
724 Handle(SelectMgr_Filter) aFilter = aModule->selectionFilter(SF_SketchPlaneFilter);
725 if (!aFilter.IsNull()) {
726 std::shared_ptr<GeomAPI_Pln> aPln;
727 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(aPln);
729 XGUI_Workshop* aWorkshop = aModule->getWorkshop();
731 aWorkshop->selectionActivate()->updateSelectionFilters();
732 aWorkshop->selectionActivate()->updateSelectionModes();
734 SessionPtr aMgr = ModelAPI_Session::get();
735 aMgr->startOperation("Change Sketch plane");
736 myOpenTransaction = true;
740 void PartSet_WidgetSketchLabel::setShowPointsState(bool theState)
742 bool aBlock = myShowPoints->blockSignals(true);
743 myShowPoints->setChecked(theState);
744 myShowPoints->blockSignals(aBlock);
747 bool PartSet_WidgetSketchLabel::restoreValueCustom()
749 if (myFeature.get()) {
750 CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
751 if (aSketch.get() && (aSketch->numberOfSubs() > 0)) {
752 AttributeStringPtr aDOFStr = aSketch->string("SolverDOF");
754 QString aVal(aDOFStr->value().c_str());
755 if (aVal.contains('=')) {
756 // to support old data
757 aVal = aVal.right(aVal.length() - aVal.lastIndexOf('='));
759 int aDoF = aVal.toInt();
761 myDoFLabel->setText(tr("Sketch is fully fixed (DoF = 0)"));
762 myShowDOFBtn->setEnabled(false);
764 myDoFLabel->setText(tr("DoF (degrees of freedom) = ") + aVal);
765 myShowDOFBtn->setEnabled(true);
770 myDoFLabel->setText("");
771 myShowDOFBtn->setEnabled(false);
778 void PartSet_WidgetSketchLabel::onShowDOF()
780 CompositeFeaturePtr aCompFeature =
781 std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
782 if (aCompFeature.get()) {
783 static const Events_ID anEvent = Events_Loop::eventByName(EVENT_GET_DOF_OBJECTS);
784 ModelAPI_EventCreator::get()->sendUpdated(aCompFeature, anEvent);
785 Events_Loop::loop()->flush(anEvent);