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>
42 #include <ModuleBase_Operation.h>
43 #include <ModuleBase_ViewerPrs.h>
44 #include <ModuleBase_Tools.h>
45 #include <ModuleBase_IModule.h>
46 #include <ModuleBase_IPropertyPanel.h>
48 #include <GeomAlgoAPI_FaceBuilder.h>
49 #include <GeomAlgoAPI_ShapeTools.h>
50 #include <GeomDataAPI_Point.h>
51 #include <GeomDataAPI_Dir.h>
52 #include <GeomAPI_XYZ.h>
53 #include <GeomAPI_Face.h>
54 #include <GeomAPI_Edge.h>
55 #include <GeomAPI_ShapeExplorer.h>
57 #include <SketchPlugin_Sketch.h>
58 #include <SketcherPrs_Tools.h>
60 #include <Precision.hxx>
64 #include <AIS_Shape.hxx>
65 #include <AIS_DimensionSelectionMode.hxx>
66 #include <Bnd_Box.hxx>
68 #include <Config_WidgetAPI.h>
69 #include <Config_PropManager.h>
72 #include <QApplication>
73 #include <QVBoxLayout>
74 #include <QHBoxLayout>
77 #include <QPushButton>
79 #include <QDoubleValidator>
83 #define DBL_MAX 1.7976931348623158e+308
86 PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent,
87 ModuleBase_IWorkshop* theWorkshop,
88 const Config_WidgetAPI* theData,
89 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& toShowConstraints)
90 : ModuleBase_WidgetValidated(theParent, theWorkshop, theData), myOpenTransaction(false),
93 QVBoxLayout* aLayout = new QVBoxLayout(this);
94 ModuleBase_Tools::zeroMargins(aLayout);
96 myStackWidget = new QStackedWidget(this);
97 myStackWidget->setContentsMargins(0,0,0,0);
98 aLayout->addWidget(myStackWidget);
100 // Define label for plane selection
101 QWidget* aFirstWgt = new QWidget(this);
103 // Size of the View control
104 mySizeOfViewWidget = new QWidget(aFirstWgt);
105 QHBoxLayout* aSizeLayout = new QHBoxLayout(mySizeOfViewWidget);
106 aSizeLayout->addWidget(new QLabel(tr("Size of the view"), mySizeOfViewWidget));
107 mySizeOfView = new QLineEdit(mySizeOfViewWidget);
109 QDoubleValidator* aValidator = new QDoubleValidator(0, DBL_MAX, 12, mySizeOfView);
110 aValidator->setLocale(ModuleBase_Tools::doubleLocale());
111 aValidator->setNotation(QDoubleValidator::StandardNotation);
112 mySizeOfView->setValidator(aValidator);
113 aSizeLayout->addWidget(mySizeOfView);
115 myPartSetMessage = new QDialog(this, Qt::ToolTip);
116 myPartSetMessage->setModal(false);
117 myPartSetMessage->setStyleSheet("background-color:lightyellow;");
118 QVBoxLayout* aMsgLay = new QVBoxLayout(myPartSetMessage);
119 QString aMsg = tr("The Sketch is created in PartSet.\n"
120 "It will be necessary to create a Part in order to use this sketch for body creation");
121 aMsgLay->addWidget(new QLabel(aMsg, myPartSetMessage));
122 myPartSetMessage->hide();
124 mySizeMessage = new QDialog(mySizeOfView, Qt::ToolTip);
125 mySizeMessage->setModal(false);
126 mySizeMessage->setStyleSheet("background-color:lightyellow;");
127 aMsgLay = new QVBoxLayout(mySizeMessage);
128 aMsg = tr("A size of Sketch view can be defined here.");
129 aMsgLay->addWidget(new QLabel(aMsg, mySizeMessage));
130 mySizeMessage->hide();
132 QString aText = translate(theData->getProperty("title"));
133 QLabel* aLabel = new QLabel(aText, aFirstWgt);
134 aLabel->setWordWrap(true);
135 QString aTooltip = translate(theData->getProperty("tooltip"));
136 aLabel->setToolTip(aTooltip);
137 aLabel->setIndent(5);
139 aLayout = new QVBoxLayout(aFirstWgt);
140 ModuleBase_Tools::zeroMargins(aLayout);
141 aLayout->addWidget(mySizeOfViewWidget);
142 aLayout->addWidget(aLabel);
144 myRemoveExternal = new QCheckBox(tr("Remove external dependencies"), aFirstWgt);
145 myRemoveExternal->setChecked(false);
146 aLayout->addWidget(myRemoveExternal);
147 myRemoveExternal->setVisible(false);
149 aLayout->addStretch(1);
151 myStackWidget->addWidget(aFirstWgt);
153 // Define widget for sketch manmagement
154 QWidget* aSecondWgt = new QWidget(this);
155 aLayout = new QVBoxLayout(aSecondWgt);
156 ModuleBase_Tools::zeroMargins(aLayout);
158 QGroupBox* aViewBox = new QGroupBox(tr("Sketcher plane"), this);
159 QVBoxLayout* aViewLayout = new QVBoxLayout(aViewBox);
161 myViewInverted = new QCheckBox(tr("Reversed"), aViewBox);
162 aViewLayout->addWidget(myViewInverted);
164 QPushButton* aSetViewBtn =
165 new QPushButton(QIcon(":icons/plane_view.png"), tr("Set plane view"), aViewBox);
166 connect(aSetViewBtn, SIGNAL(clicked(bool)), this, SLOT(onSetPlaneView()));
167 aViewLayout->addWidget(aSetViewBtn);
169 aLayout->addWidget(aViewBox);
171 QMap<PartSet_Tools::ConstraintVisibleState, QString> aStates;
172 aStates[PartSet_Tools::Geometrical] = tr("Show geometrical constraints");
173 aStates[PartSet_Tools::Dimensional] = tr("Show dimensional constraints");
174 aStates[PartSet_Tools::Expressions] = tr("Show existing expressions");
176 QMap<PartSet_Tools::ConstraintVisibleState, QString>::const_iterator anIt = aStates.begin(),
177 aLast = aStates.end();
178 for (; anIt != aLast; anIt++) {
179 QCheckBox* aShowConstraints = new QCheckBox(anIt.value(), this);
180 connect(aShowConstraints, SIGNAL(toggled(bool)), this, SLOT(onShowConstraint(bool)));
181 aLayout->addWidget(aShowConstraints);
183 PartSet_Tools::ConstraintVisibleState aState = anIt.key();
184 myShowConstraints[aState] = aShowConstraints;
186 if (toShowConstraints.contains(aState))
187 aShowConstraints->setChecked(toShowConstraints[aState]);
189 myShowPoints = new QCheckBox(tr("Show free points"), this);
190 connect(myShowPoints, SIGNAL(toggled(bool)), this, SIGNAL(showFreePoints(bool)));
191 aLayout->addWidget(myShowPoints);
193 myAutoConstraints = new QCheckBox(tr("Automatic constraints"), this);
194 myAutoConstraints->setToolTip(tr("Automatic vertical and horizontal constraints"));
195 connect(myAutoConstraints, SIGNAL(toggled(bool)), this, SIGNAL(autoConstraints(bool)));
196 aLayout->addWidget(myAutoConstraints);
198 QPushButton* aPlaneBtn = new QPushButton(tr("Change sketch plane"), aSecondWgt);
199 connect(aPlaneBtn, SIGNAL(clicked(bool)), SLOT(onChangePlane()));
200 aLayout->addWidget(aPlaneBtn);
202 myDoFLabel = new QLabel("", aSecondWgt);
203 aLayout->addWidget(myDoFLabel);
205 myStackWidget->addWidget(aSecondWgt);
206 //setLayout(aLayout);
208 myPreviewPlanes = new PartSet_PreviewPlanes();
211 PartSet_WidgetSketchLabel::~PartSet_WidgetSketchLabel()
215 bool PartSet_WidgetSketchLabel::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValues,
216 const bool theToValidate)
218 // do not use the given selection if the plane of the sketch has been already set.
219 // If this check is absent, a selected plane in the viewer can be set in the sketch
220 // even if the sketch is built on another plane.
224 ModuleBase_ViewerPrsPtr aPrs = theValues.first();
225 bool aDone = setSelectionInternal(theValues, theToValidate);
227 updateByPlaneSelected(aPrs);
231 QList<QWidget*> PartSet_WidgetSketchLabel::getControls() const
233 QList<QWidget*> aResult;
234 aResult << myStackWidget;
238 bool PartSet_WidgetSketchLabel::processSelection()
240 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
244 QList<ModuleBase_ViewerPrsPtr> aSelected = getFilteredSelected();
246 if (aSelected.empty())
248 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
249 bool aDone = setSelectionInternal(aSelected, false);
251 updateByPlaneSelected(aPrs);
252 updateObject(myFeature);
258 void PartSet_WidgetSketchLabel::onShowConstraint(bool theOn)
260 QCheckBox* aSenderCheckBox = qobject_cast<QCheckBox*>(sender());
262 QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*>::const_iterator
263 anIt = myShowConstraints.begin(), aLast = myShowConstraints.end();
265 PartSet_Tools::ConstraintVisibleState aState = PartSet_Tools::Geometrical;
267 for (; anIt != aLast && !aFound; anIt++) {
268 aFound = anIt.value() == aSenderCheckBox;
273 emit showConstraintToggled(aState, theOn);
276 void PartSet_WidgetSketchLabel::blockAttribute(const AttributePtr& theAttribute,
277 const bool& theToBlock, bool& isFlushesActived,
278 bool& isAttributeSetInitializedBlocked,
279 bool& isAttributeSendUpdatedBlocked)
281 ModuleBase_WidgetValidated::blockAttribute(theAttribute, theToBlock, isFlushesActived,
282 isAttributeSetInitializedBlocked,
283 isAttributeSendUpdatedBlocked);
284 // We do not restore the previous state of isAttributeSetInitializedBlocked for each of
285 // attributes. It it is necessary, these states should be append to the method attributes
286 // or stored in the widget
288 std::list<AttributePtr> anAttributes = myFeature->data()->attributes("");
289 std::list<AttributePtr>::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end();
291 for(; anIt != aLast; anIt++) {
292 AttributePtr anAttribute = *anIt;
294 anAttribute->blockSetInitialized(true);
296 anAttribute->blockSetInitialized(isAttributeSetInitializedBlocked);
300 bool PartSet_WidgetSketchLabel::setSelectionInternal(
301 const QList<ModuleBase_ViewerPrsPtr>& theValues,
302 const bool theToValidate)
305 if (theValues.empty()) {
306 // In order to make reselection possible, set empty object and shape should be done
307 setSelectionCustom(std::shared_ptr<ModuleBase_ViewerPrs>(
308 new ModuleBase_ViewerPrs(ObjectPtr(), GeomShapePtr(), NULL)));
312 // it removes the processed value from the parameters list
313 ModuleBase_ViewerPrsPtr aValue = theValues.first();//.takeFirst();
314 if (!theToValidate || isValidInFilters(aValue)) {
315 myIsSelection = true;
316 aDone = setSelectionCustom(aValue);
317 myIsSelection = false;
324 void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrsPtr& thePrs)
326 GeomPlanePtr aPlane = plane();
330 myPartSetMessage->hide();
331 mySizeMessage->hide();
333 // 1. hide main planes if they have been displayed and display sketch preview plane
334 myPreviewPlanes->erasePreviewPlanes(myWorkshop);
336 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
338 CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
339 bool isSetSizeOfView = false;
340 double aSizeOfView = 0;
341 QString aSizeOfViewStr = mySizeOfView->text();
342 if (!aSizeOfViewStr.isEmpty()) {
343 aSizeOfView = aSizeOfViewStr.toDouble(&isSetSizeOfView);
344 if (isSetSizeOfView && aSizeOfView <= 0) {
345 isSetSizeOfView = false;
348 aModule->sketchMgr()->previewSketchPlane()->setSizeOfView(aSizeOfView, isSetSizeOfView);
349 aModule->sketchMgr()->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
351 // 2. if the planes were displayed, change the view projection
353 std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
354 gp_XYZ aXYZ = aDir->impl<gp_Dir>().XYZ();
357 // Rotate view if the sketcher plane is selected only from preview planes
358 // Preview planes are created only if there is no any shape
359 bool aRotate = Config_PropManager::boolean(SKETCH_TAB_NAME, "rotate_to_plane");
361 myWorkshop->viewer()->setViewProjection(aXYZ.X(), aXYZ.Y(), aXYZ.Z(), aTwist);
363 QString aSizeOfViewStr = mySizeOfView->text();
364 if (!aSizeOfViewStr.isEmpty()) {
366 double aSizeOfView = aSizeOfViewStr.toDouble(&isOk);
367 if (isOk && aSizeOfView > 0) {
368 Handle(V3d_View) aView3d = myWorkshop->viewer()->activeView();
369 if (!aView3d.IsNull()) {
371 double aHalfSize = aSizeOfView/2.0;
372 aBndBox.Update(-aHalfSize, -aHalfSize, -aHalfSize, aHalfSize, aHalfSize, aHalfSize);
373 aView3d->FitAll(aBndBox, 0.01, false);
377 if (myOpenTransaction) {
378 SessionPtr aMgr = ModelAPI_Session::get();
379 aMgr->finishOperation();
380 myOpenTransaction = false;
382 // 3. Clear text in the label
383 myStackWidget->setCurrentIndex(1);
384 //myLabel->setText("");
385 //myLabel->setToolTip("");
386 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
388 // 5. Clear selection mode and define sketching mode
389 emit planeSelected(plane());
390 // after the plane is selected in the sketch, the sketch selection should be activated
391 // it can not be performed in the sketch label widget because, we don't need to switch off
392 // the selection by any label deactivation, but need to switch it off by stop the sketch
393 myWorkshop->selectionActivate()->updateSelectionFilters();
394 myWorkshop->selectionActivate()->updateSelectionModes();
397 aModule->onViewTransformed();
399 // 6. Update sketcher actions
400 XGUI_ActionsMgr* anActMgr = aWorkshop->actionsMgr();
402 myWorkshop->updateCommandStatus();
403 aWorkshop->selector()->clearSelection();
404 myWorkshop->viewer()->update();
406 myRemoveExternal->setVisible(false);
409 std::shared_ptr<GeomAPI_Pln> PartSet_WidgetSketchLabel::plane() const
411 CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
412 return PartSet_Tools::sketchPlane(aSketch);
415 bool PartSet_WidgetSketchLabel::focusTo()
417 ModuleBase_Tools::setFocus(myStackWidget, "PartSet_WidgetSketchLabel::focusTo()");
421 void PartSet_WidgetSketchLabel::enableFocusProcessing()
423 myStackWidget->installEventFilter(this);
426 void PartSet_WidgetSketchLabel::storeAttributeValue(const AttributePtr& theAttribute)
428 ModuleBase_WidgetValidated::storeAttributeValue(theAttribute);
431 void PartSet_WidgetSketchLabel::restoreAttributeValue(const AttributePtr& theAttribute,
434 ModuleBase_WidgetValidated::restoreAttributeValue(theAttribute, theValid);
436 // it is not necessary to save the previous plane value because the plane is chosen once
437 DataPtr aData = feature()->data();
438 AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
439 (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
441 ResultPtr anEmptyResult;
442 GeomShapePtr anEmptyShape;
443 aSelAttr->setValue(anEmptyResult, anEmptyShape);
447 bool PartSet_WidgetSketchLabel::setSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
449 if (myIsSelection && myRemoveExternal->isVisible()) {
450 if (myRemoveExternal->isChecked()) {
451 myFeature->customAction(SketchPlugin_Sketch::ACTION_REMOVE_EXTERNAL());
454 return fillSketchPlaneBySelection(thePrs);
457 bool PartSet_WidgetSketchLabel::canFillSketch(const ModuleBase_ViewerPrsPtr& thePrs)
459 bool aCanFillSketch = true;
460 // avoid any selection on sketch object
461 ObjectPtr anObject = thePrs->object();
462 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
464 FeaturePtr aFeature = ModelAPI_Feature::feature(aResult);
465 if (aFeature->getKind() == SketchPlugin_Sketch::ID())
466 aCanFillSketch = false;
468 // check plane or planar face of any non-sketch object
469 if (aCanFillSketch) {
470 std::shared_ptr<GeomAPI_Face> aGeomFace;
472 GeomShapePtr aGeomShape = thePrs->shape();
473 if ((!aGeomShape.get() || aGeomShape->isNull()) && aResult.get()) {
474 aGeomShape = aResult->shape();
477 if (aGeomShape.get() && aGeomShape->shapeType() == GeomAPI_Shape::FACE) {
478 std::shared_ptr<GeomAPI_Face> aGeomFace(new GeomAPI_Face(aGeomShape));
479 aCanFillSketch = aGeomFace.get() && aGeomFace->isPlanar();
482 aCanFillSketch = false;
484 return aCanFillSketch;
487 bool PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(const ModuleBase_ViewerPrsPtr& thePrs)
489 bool isOwnerSet = false;
491 const GeomShapePtr& aShape = thePrs->shape();
492 std::shared_ptr<GeomAPI_Dir> aDir;
494 if (aShape.get() && !aShape->isNull()) {
495 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
496 aDir = setSketchPlane(aTDShape);
497 isOwnerSet = aDir.get();
499 if (thePrs->object() && (feature() != thePrs->object())) {
500 FeaturePtr aFeature = ModelAPI_Feature::feature(thePrs->object());
501 DataPtr aData = feature()->data();
502 AttributeSelectionPtr aSelAttr =
503 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
504 (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
505 if (aSelAttr.get()) {
506 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePrs->object());
508 GeomShapePtr aShapePtr;
509 if (!aShape.get() || aShape->isNull()) { // selection happens in the OCC viewer
510 aShapePtr = ModelAPI_Tools::shape(aRes);
512 else { // selection happens in OB browser
515 if (aShapePtr.get() && aShapePtr->isFace()) {
516 const TopoDS_Shape& aTDShape = aShapePtr->impl<TopoDS_Shape>();
517 setSketchPlane(aTDShape);
518 aSelAttr->setValue(aRes, aShapePtr);
523 aSelAttr->setValue(aFeature, GeomShapePtr());
524 GeomShapePtr aShape = aSelAttr->value();
525 if (!aShape.get() && aSelAttr->contextFeature().get() &&
526 aSelAttr->contextFeature()->firstResult().get()) {
527 aShape = aSelAttr->contextFeature()->firstResult()->shape();
529 if (aShape.get() && aShape->isPlanar()) {
530 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
531 setSketchPlane(aTDShape);
540 void PartSet_WidgetSketchLabel::activateCustom()
542 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
544 bool isBlocked = myAutoConstraints->blockSignals(true);
545 myAutoConstraints->setChecked(aModule->sketchReentranceMgr()->isAutoConstraints());
546 myAutoConstraints->blockSignals(isBlocked);
549 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
551 myStackWidget->setCurrentIndex(1);
555 myStackWidget->setCurrentIndex(0);
556 bool aBodyIsVisualized = myPreviewPlanes->hasVisualizedBodies(myWorkshop);
558 // Clear previous selection mode It is necessary for correct activation of preview planes
559 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
560 XGUI_Displayer* aDisp = aWorkshop->displayer();
561 aWorkshop->selectionActivate()->activateObjects(QIntList(), aDisp->displayedObjects(), false);
563 if (!aBodyIsVisualized) {
564 // We have to select a plane before any operation
565 myPreviewPlanes->showPreviewPlanes(myWorkshop);
566 mySizeOfViewWidget->setVisible(true);
569 mySizeOfViewWidget->setVisible(false);
572 void PartSet_WidgetSketchLabel::showEvent(QShowEvent* theEvent)
574 if (mySizeOfViewWidget->isVisible()) {
575 DocumentPtr aDoc = feature()->document();
576 DocumentPtr aModDoc = ModelAPI_Session::get()->moduleDocument();
577 if (aModDoc == aDoc) {
578 myPartSetMessage->move(mapToGlobal(geometry().bottomLeft()));
579 myPartSetMessage->show();
581 mySizeMessage->move(mySizeOfView->mapToGlobal(mySizeOfView->geometry().center()));
582 mySizeMessage->show();
587 void PartSet_WidgetSketchLabel::deactivate()
589 ModuleBase_WidgetValidated::deactivate();
590 bool aHidePreview = myPreviewPlanes->isPreviewDisplayed();
591 myPreviewPlanes->erasePreviewPlanes(myWorkshop);
594 myWorkshop->viewer()->update();
596 if (myOpenTransaction) {
597 SessionPtr aMgr = ModelAPI_Session::get();
598 aMgr->finishOperation();
599 myOpenTransaction = false;
603 void PartSet_WidgetSketchLabel::selectionModes(int& theModuleSelectionModes, QIntList& theModes)
605 theModuleSelectionModes = -1;
606 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
608 theModes << TopAbs_FACE;
611 void PartSet_WidgetSketchLabel::selectionFilters(QIntList& theModuleSelectionFilters,
612 SelectMgr_ListOfFilter& theSelectionFilters)
614 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
617 return ModuleBase_WidgetValidated::selectionFilters(theModuleSelectionFilters,
618 theSelectionFilters);
621 std::shared_ptr<GeomAPI_Dir>
622 PartSet_WidgetSketchLabel::setSketchPlane(const TopoDS_Shape& theShape)
624 if (theShape.IsNull())
625 return std::shared_ptr<GeomAPI_Dir>();
627 // get selected shape
628 std::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
629 aGShape->setImpl(new TopoDS_Shape(theShape));
631 // get plane parameters
632 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aGShape));
633 std::shared_ptr<GeomAPI_Pln> aPlane = aFace->getPlane();
635 return std::shared_ptr<GeomAPI_Dir>();
636 return setSketchPlane(aPlane);
639 std::shared_ptr<GeomAPI_Dir>
640 PartSet_WidgetSketchLabel::setSketchPlane(std::shared_ptr<GeomAPI_Pln> thePlane)
642 // set plane parameters to feature
643 std::shared_ptr<ModelAPI_Data> aData = feature()->data();
644 double anA, aB, aC, aD;
645 thePlane->coefficients(anA, aB, aC, aD);
647 // calculate attributes of the sketch
648 std::shared_ptr<GeomAPI_Dir> aNormDir(new GeomAPI_Dir(anA, aB, aC));
649 std::shared_ptr<GeomAPI_XYZ> aCoords = aNormDir->xyz();
650 std::shared_ptr<GeomAPI_XYZ> aZero(new GeomAPI_XYZ(0, 0, 0));
651 aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero));
652 std::shared_ptr<GeomAPI_Pnt> anOrigPnt(new GeomAPI_Pnt(aCoords));
653 // X axis is preferable to be dirX on the sketch
654 const double tol = Precision::Confusion();
655 bool isX = fabs(fabs(anA) - 1.0) < tol && fabs(aB) < tol && fabs(aC) < tol;
656 std::shared_ptr<GeomAPI_Dir> aTempDir(
657 isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0));
658 std::shared_ptr<GeomAPI_Dir> aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir)));
659 std::shared_ptr<GeomAPI_Dir> aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir)));
661 std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
662 aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
663 anOrigin->setValue(anOrigPnt);
664 std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
665 aData->attribute(SketchPlugin_Sketch::NORM_ID()));
666 aNormal->setValue(aNormDir);
667 std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
668 aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
669 aDirX->setValue(aXDir);
670 std::shared_ptr<GeomAPI_Dir> aDir = thePlane->direction();
674 void PartSet_WidgetSketchLabel::onSetPlaneView()
676 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
678 std::shared_ptr<GeomAPI_Dir> aDirection = aPlane->direction();
679 gp_Dir aDir = aDirection->impl<gp_Dir>();
680 if (myViewInverted->isChecked())
682 myWorkshop->viewer()->setViewProjection(aDir.X(), aDir.Y(), aDir.Z(), 0.);
683 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
685 aModule->onViewTransformed();
690 //******************************************************
691 QList<std::shared_ptr<ModuleBase_ViewerPrs>> PartSet_WidgetSketchLabel::findCircularEdgesInPlane()
693 QList<std::shared_ptr<ModuleBase_ViewerPrs>> aResult;
694 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
695 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
696 QObjectPtrList aDispObjects = aDisplayer->displayedObjects();
698 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
699 foreach(ObjectPtr aObj, aDispObjects) {
700 ResultPtr aResObj = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
702 GeomShapePtr aShape = aResObj->shape();
704 GeomAPI_ShapeExplorer aExplorer(aShape, GeomAPI_Shape::EDGE);
705 for(; aExplorer.more(); aExplorer.next()) {
706 GeomShapePtr aEdgeShape = aExplorer.current();
707 GeomAPI_Edge anEdge(aEdgeShape);
708 if ((anEdge.isCircle() || anEdge.isArc() || anEdge.isEllipse()) &&
709 anEdge.isInPlane(aPlane)) {
710 bool isContains = false;
711 // Check that edge is not used.
712 // It is possible that the same edge will be taken from different faces
713 foreach(std::shared_ptr<ModuleBase_ViewerPrs> aPrs, aResult) {
714 GeomAPI_Edge aUsedEdge(aPrs->shape());
715 if (aUsedEdge.isEqual(aEdgeShape)) {
721 std::shared_ptr<ModuleBase_ViewerPrs>
722 aPrs(new ModuleBase_ViewerPrs(aResObj, aEdgeShape));
723 aResult.append(aPrs);
733 //******************************************************
734 void PartSet_WidgetSketchLabel::onChangePlane()
736 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
738 mySizeOfViewWidget->setVisible(false);
739 myRemoveExternal->setVisible(true);
740 myStackWidget->setCurrentIndex(0);
742 bool aBodyIsVisualized = myPreviewPlanes->hasVisualizedBodies(myWorkshop);
744 if (!aBodyIsVisualized) {
745 // We have to select a plane before any operation
746 myPreviewPlanes->showPreviewPlanes(myWorkshop);
749 CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
750 PartSet_Tools::nullifySketchPlane(aSketch);
752 Handle(SelectMgr_Filter) aFilter = aModule->selectionFilter(SF_SketchPlaneFilter);
753 if (!aFilter.IsNull()) {
754 std::shared_ptr<GeomAPI_Pln> aPln;
755 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(aPln);
757 XGUI_Workshop* aWorkshop = aModule->getWorkshop();
759 aWorkshop->selectionActivate()->updateSelectionFilters();
760 aWorkshop->selectionActivate()->updateSelectionModes();
762 SessionPtr aMgr = ModelAPI_Session::get();
763 aMgr->startOperation("Change Sketch plane");
764 myOpenTransaction = true;
765 myWorkshop->viewer()->update();
769 void PartSet_WidgetSketchLabel::setShowPointsState(bool theState)
771 bool aBlock = myShowPoints->blockSignals(true);
772 myShowPoints->setChecked(theState);
773 myShowPoints->blockSignals(aBlock);
776 bool PartSet_WidgetSketchLabel::restoreValueCustom()
778 if (myFeature.get()) {
779 CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
780 if (aSketch.get() && (aSketch->numberOfSubs() > 0)) {
781 AttributeStringPtr aDOFStr = aSketch->string("SolverDOF");
783 QString aVal(aDOFStr->value().c_str());
784 if (aVal.contains('=')) {
785 // to support old data
786 aVal = aVal.right(aVal.length() - aVal.lastIndexOf('='));
788 int aDoF = aVal.toInt();
790 myDoFLabel->setText(tr("Sketch is fully fixed (DoF = 0)"));
792 myDoFLabel->setText(tr("DoF (degrees of freedom) = ") + aVal);
797 myDoFLabel->setText("");