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>
78 #include <QStackedWidget>
80 #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 myPartSetMessage = new QDialog(this, Qt::ToolTip);
117 myPartSetMessage->setModal(false);
118 myPartSetMessage->setStyleSheet("background-color:lightyellow;");
119 QVBoxLayout* aMsgLay = new QVBoxLayout(myPartSetMessage);
120 QString aMsg = tr("The Sketch is created in PartSet.\n"
121 "It will be necessary to create a Part in order to use this sketch for body creation");
122 aMsgLay->addWidget(new QLabel(aMsg, myPartSetMessage));
123 myPartSetMessage->hide();
125 mySizeMessage = new QDialog(mySizeOfView, Qt::ToolTip);
126 mySizeMessage->setModal(false);
127 mySizeMessage->setStyleSheet("background-color:lightyellow;");
128 aMsgLay = new QVBoxLayout(mySizeMessage);
129 aMsg = tr("A size of Sketch view can be defined here.");
130 aMsgLay->addWidget(new QLabel(aMsg, mySizeMessage));
131 mySizeMessage->hide();
133 QString aText = translate(theData->getProperty("title"));
134 QLabel* aLabel = new QLabel(aText, aFirstWgt);
135 aLabel->setWordWrap(true);
136 QString aTooltip = translate(theData->getProperty("tooltip"));
137 aLabel->setToolTip(aTooltip);
138 aLabel->setIndent(5);
140 aLayout = new QVBoxLayout(aFirstWgt);
141 ModuleBase_Tools::zeroMargins(aLayout);
142 aLayout->addWidget(mySizeOfViewWidget);
143 aLayout->addWidget(aLabel);
145 myRemoveExternal = new QCheckBox(tr("Remove external dependencies"), aFirstWgt);
146 myRemoveExternal->setChecked(false);
147 aLayout->addWidget(myRemoveExternal);
148 myRemoveExternal->setVisible(false);
150 aLayout->addStretch(1);
152 myStackWidget->addWidget(aFirstWgt);
154 // Define widget for sketch manmagement
155 QWidget* aSecondWgt = new QWidget(this);
156 aLayout = new QVBoxLayout(aSecondWgt);
157 ModuleBase_Tools::zeroMargins(aLayout);
159 QGroupBox* aViewBox = new QGroupBox(tr("Sketcher plane"), this);
160 QVBoxLayout* aViewLayout = new QVBoxLayout(aViewBox);
162 myViewInverted = new QCheckBox(tr("Reversed"), aViewBox);
163 aViewLayout->addWidget(myViewInverted);
165 QPushButton* aSetViewBtn =
166 new QPushButton(QIcon(":icons/plane_view.png"), tr("Set plane view"), aViewBox);
167 connect(aSetViewBtn, SIGNAL(clicked(bool)), this, SLOT(onSetPlaneView()));
168 aViewLayout->addWidget(aSetViewBtn);
170 aLayout->addWidget(aViewBox);
172 QMap<PartSet_Tools::ConstraintVisibleState, QString> aStates;
173 aStates[PartSet_Tools::Geometrical] = tr("Show geometrical constraints");
174 aStates[PartSet_Tools::Dimensional] = tr("Show dimensional constraints");
175 aStates[PartSet_Tools::Expressions] = tr("Show existing expressions");
177 QMap<PartSet_Tools::ConstraintVisibleState, QString>::const_iterator anIt = aStates.begin(),
178 aLast = aStates.end();
179 for (; anIt != aLast; anIt++) {
180 QCheckBox* aShowConstraints = new QCheckBox(anIt.value(), this);
181 connect(aShowConstraints, SIGNAL(toggled(bool)), this, SLOT(onShowConstraint(bool)));
182 aLayout->addWidget(aShowConstraints);
184 PartSet_Tools::ConstraintVisibleState aState = anIt.key();
185 myShowConstraints[aState] = aShowConstraints;
187 if (toShowConstraints.contains(aState))
188 aShowConstraints->setChecked(toShowConstraints[aState]);
190 myShowPoints = new QCheckBox(tr("Show free points"), this);
191 connect(myShowPoints, SIGNAL(toggled(bool)), this, SIGNAL(showFreePoints(bool)));
192 aLayout->addWidget(myShowPoints);
194 myAutoConstraints = new QCheckBox(tr("Automatic constraints"), this);
195 myAutoConstraints->setToolTip(tr("Automatic vertical and horizontal constraints"));
196 connect(myAutoConstraints, SIGNAL(toggled(bool)), this, SIGNAL(autoConstraints(bool)));
197 aLayout->addWidget(myAutoConstraints);
199 QPushButton* aPlaneBtn = new QPushButton(tr("Change sketch plane"), aSecondWgt);
200 connect(aPlaneBtn, SIGNAL(clicked(bool)), SLOT(onChangePlane()));
201 aLayout->addWidget(aPlaneBtn);
203 myDoFLabel = new QLabel("", aSecondWgt);
204 aLayout->addWidget(myDoFLabel);
206 myStackWidget->addWidget(aSecondWgt);
207 //setLayout(aLayout);
209 myPreviewPlanes = new PartSet_PreviewPlanes();
212 PartSet_WidgetSketchLabel::~PartSet_WidgetSketchLabel()
216 bool PartSet_WidgetSketchLabel::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValues,
217 const bool theToValidate)
219 // do not use the given selection if the plane of the sketch has been already set.
220 // If this check is absent, a selected plane in the viewer can be set in the sketch
221 // even if the sketch is built on another plane.
225 ModuleBase_ViewerPrsPtr aPrs = theValues.first();
226 bool aDone = setSelectionInternal(theValues, theToValidate);
228 updateByPlaneSelected(aPrs);
232 QList<QWidget*> PartSet_WidgetSketchLabel::getControls() const
234 QList<QWidget*> aResult;
235 aResult << myStackWidget;
239 bool PartSet_WidgetSketchLabel::processSelection()
241 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
245 QList<ModuleBase_ViewerPrsPtr> aSelected = getFilteredSelected();
247 if (aSelected.empty())
249 ModuleBase_ViewerPrsPtr aPrs = aSelected.first();
250 bool aDone = setSelectionInternal(aSelected, false);
252 updateByPlaneSelected(aPrs);
253 updateObject(myFeature);
259 void PartSet_WidgetSketchLabel::onShowConstraint(bool theOn)
261 QCheckBox* aSenderCheckBox = qobject_cast<QCheckBox*>(sender());
263 QMap<PartSet_Tools::ConstraintVisibleState, QCheckBox*>::const_iterator
264 anIt = myShowConstraints.begin(), aLast = myShowConstraints.end();
266 PartSet_Tools::ConstraintVisibleState aState = PartSet_Tools::Geometrical;
268 for (; anIt != aLast && !aFound; anIt++) {
269 aFound = anIt.value() == aSenderCheckBox;
274 emit showConstraintToggled(aState, theOn);
277 void PartSet_WidgetSketchLabel::blockAttribute(const AttributePtr& theAttribute,
278 const bool& theToBlock, bool& isFlushesActived,
279 bool& isAttributeSetInitializedBlocked,
280 bool& isAttributeSendUpdatedBlocked)
282 ModuleBase_WidgetValidated::blockAttribute(theAttribute, theToBlock, isFlushesActived,
283 isAttributeSetInitializedBlocked,
284 isAttributeSendUpdatedBlocked);
285 // We do not restore the previous state of isAttributeSetInitializedBlocked for each of
286 // attributes. It it is necessary, these states should be append to the method attributes
287 // or stored in the widget
289 std::list<AttributePtr> anAttributes = myFeature->data()->attributes("");
290 std::list<AttributePtr>::const_iterator anIt = anAttributes.begin(), aLast = anAttributes.end();
292 for(; anIt != aLast; anIt++) {
293 AttributePtr anAttribute = *anIt;
295 anAttribute->blockSetInitialized(true);
297 anAttribute->blockSetInitialized(isAttributeSetInitializedBlocked);
301 bool PartSet_WidgetSketchLabel::setSelectionInternal(
302 const QList<ModuleBase_ViewerPrsPtr>& theValues,
303 const bool theToValidate)
306 if (theValues.empty()) {
307 // In order to make reselection possible, set empty object and shape should be done
308 setSelectionCustom(std::shared_ptr<ModuleBase_ViewerPrs>(
309 new ModuleBase_ViewerPrs(ObjectPtr(), GeomShapePtr(), NULL)));
313 // it removes the processed value from the parameters list
314 ModuleBase_ViewerPrsPtr aValue = theValues.first();//.takeFirst();
315 if (!theToValidate || isValidInFilters(aValue)) {
316 myIsSelection = true;
317 aDone = setSelectionCustom(aValue);
318 myIsSelection = false;
325 void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrsPtr& thePrs)
327 GeomPlanePtr aPlane = plane();
331 myPartSetMessage->hide();
332 mySizeMessage->hide();
334 // 1. hide main planes if they have been displayed and display sketch preview plane
335 myPreviewPlanes->erasePreviewPlanes(myWorkshop);
337 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
339 CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
340 bool isSetSizeOfView = false;
341 double aSizeOfView = 0;
342 QString aSizeOfViewStr = mySizeOfView->text();
343 if (!aSizeOfViewStr.isEmpty()) {
344 aSizeOfView = aSizeOfViewStr.toDouble(&isSetSizeOfView);
345 if (isSetSizeOfView && aSizeOfView <= 0) {
346 isSetSizeOfView = false;
349 aModule->sketchMgr()->previewSketchPlane()->setSizeOfView(aSizeOfView, isSetSizeOfView);
350 aModule->sketchMgr()->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
352 // 2. if the planes were displayed, change the view projection
354 std::shared_ptr<GeomAPI_Dir> aDir = aPlane->direction();
355 gp_XYZ aXYZ = aDir->impl<gp_Dir>().XYZ();
358 // Rotate view if the sketcher plane is selected only from preview planes
359 // Preview planes are created only if there is no any shape
360 bool aRotate = Config_PropManager::boolean(SKETCH_TAB_NAME, "rotate_to_plane");
362 myWorkshop->viewer()->setViewProjection(aXYZ.X(), aXYZ.Y(), aXYZ.Z(), aTwist);
364 QString aSizeOfViewStr = mySizeOfView->text();
365 if (!aSizeOfViewStr.isEmpty()) {
367 double aSizeOfView = aSizeOfViewStr.toDouble(&isOk);
368 if (isOk && aSizeOfView > 0) {
369 Handle(V3d_View) aView3d = myWorkshop->viewer()->activeView();
370 if (!aView3d.IsNull()) {
372 double aHalfSize = aSizeOfView/2.0;
373 aBndBox.Update(-aHalfSize, -aHalfSize, -aHalfSize, aHalfSize, aHalfSize, aHalfSize);
374 aView3d->FitAll(aBndBox, 0.01, false);
378 if (myOpenTransaction) {
379 SessionPtr aMgr = ModelAPI_Session::get();
380 aMgr->finishOperation();
381 myOpenTransaction = false;
383 // 3. Clear text in the label
384 myStackWidget->setCurrentIndex(1);
385 //myLabel->setText("");
386 //myLabel->setToolTip("");
387 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
389 // 5. Clear selection mode and define sketching mode
390 emit planeSelected(plane());
391 // after the plane is selected in the sketch, the sketch selection should be activated
392 // it can not be performed in the sketch label widget because, we don't need to switch off
393 // the selection by any label deactivation, but need to switch it off by stop the sketch
394 myWorkshop->selectionActivate()->updateSelectionFilters();
395 myWorkshop->selectionActivate()->updateSelectionModes();
398 aModule->onViewTransformed();
400 // 6. Update sketcher actions
401 XGUI_ActionsMgr* anActMgr = aWorkshop->actionsMgr();
403 myWorkshop->updateCommandStatus();
404 aWorkshop->selector()->clearSelection();
405 myWorkshop->viewer()->update();
407 myRemoveExternal->setVisible(false);
410 std::shared_ptr<GeomAPI_Pln> PartSet_WidgetSketchLabel::plane() const
412 CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
413 return PartSet_Tools::sketchPlane(aSketch);
416 bool PartSet_WidgetSketchLabel::focusTo()
418 ModuleBase_Tools::setFocus(myStackWidget, "PartSet_WidgetSketchLabel::focusTo()");
422 void PartSet_WidgetSketchLabel::enableFocusProcessing()
424 myStackWidget->installEventFilter(this);
427 void PartSet_WidgetSketchLabel::storeAttributeValue(const AttributePtr& theAttribute)
429 ModuleBase_WidgetValidated::storeAttributeValue(theAttribute);
432 void PartSet_WidgetSketchLabel::restoreAttributeValue(const AttributePtr& theAttribute,
435 ModuleBase_WidgetValidated::restoreAttributeValue(theAttribute, theValid);
437 // it is not necessary to save the previous plane value because the plane is chosen once
438 DataPtr aData = feature()->data();
439 AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
440 (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
442 ResultPtr anEmptyResult;
443 GeomShapePtr anEmptyShape;
444 aSelAttr->setValue(anEmptyResult, anEmptyShape);
448 bool PartSet_WidgetSketchLabel::setSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
450 if (myIsSelection && myRemoveExternal->isVisible()) {
451 if (myRemoveExternal->isChecked()) {
452 myFeature->customAction(SketchPlugin_Sketch::ACTION_REMOVE_EXTERNAL());
455 return fillSketchPlaneBySelection(thePrs);
458 bool PartSet_WidgetSketchLabel::canFillSketch(const ModuleBase_ViewerPrsPtr& thePrs)
460 bool aCanFillSketch = true;
461 // avoid any selection on sketch object
462 ObjectPtr anObject = thePrs->object();
463 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
465 FeaturePtr aFeature = ModelAPI_Feature::feature(aResult);
466 if (aFeature->getKind() == SketchPlugin_Sketch::ID())
467 aCanFillSketch = false;
469 // check plane or planar face of any non-sketch object
470 if (aCanFillSketch) {
471 std::shared_ptr<GeomAPI_Face> aGeomFace;
473 GeomShapePtr aGeomShape = thePrs->shape();
474 if ((!aGeomShape.get() || aGeomShape->isNull()) && aResult.get()) {
475 aGeomShape = aResult->shape();
478 if (aGeomShape.get() && aGeomShape->shapeType() == GeomAPI_Shape::FACE) {
479 std::shared_ptr<GeomAPI_Face> aGeomFace(new GeomAPI_Face(aGeomShape));
480 aCanFillSketch = aGeomFace.get() && aGeomFace->isPlanar();
483 aCanFillSketch = false;
485 return aCanFillSketch;
488 bool PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(const ModuleBase_ViewerPrsPtr& thePrs)
490 bool isOwnerSet = false;
492 const GeomShapePtr& aShape = thePrs->shape();
493 std::shared_ptr<GeomAPI_Dir> aDir;
495 if (aShape.get() && !aShape->isNull()) {
496 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
497 aDir = setSketchPlane(aTDShape);
498 isOwnerSet = aDir.get();
500 if (thePrs->object() && (feature() != thePrs->object())) {
501 FeaturePtr aFeature = ModelAPI_Feature::feature(thePrs->object());
502 DataPtr aData = feature()->data();
503 AttributeSelectionPtr aSelAttr =
504 std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
505 (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
506 if (aSelAttr.get()) {
507 ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(thePrs->object());
509 GeomShapePtr aShapePtr;
510 if (!aShape.get() || aShape->isNull()) { // selection happens in the OCC viewer
511 aShapePtr = ModelAPI_Tools::shape(aRes);
513 else { // selection happens in OB browser
516 if (aShapePtr.get() && aShapePtr->isFace()) {
517 const TopoDS_Shape& aTDShape = aShapePtr->impl<TopoDS_Shape>();
518 setSketchPlane(aTDShape);
519 aSelAttr->setValue(aRes, aShapePtr);
524 aSelAttr->setValue(aFeature, GeomShapePtr());
525 GeomShapePtr aShape = aSelAttr->value();
526 if (!aShape.get() && aSelAttr->contextFeature().get() &&
527 aSelAttr->contextFeature()->firstResult().get()) {
528 aShape = aSelAttr->contextFeature()->firstResult()->shape();
530 if (aShape.get() && aShape->isPlanar()) {
531 const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
532 setSketchPlane(aTDShape);
541 void PartSet_WidgetSketchLabel::activateCustom()
543 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
545 bool isBlocked = myAutoConstraints->blockSignals(true);
546 myAutoConstraints->setChecked(aModule->sketchReentranceMgr()->isAutoConstraints());
547 myAutoConstraints->blockSignals(isBlocked);
550 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
552 myStackWidget->setCurrentIndex(1);
556 myStackWidget->setCurrentIndex(0);
557 bool aBodyIsVisualized = myPreviewPlanes->hasVisualizedBodies(myWorkshop);
559 // Clear previous selection mode It is necessary for correct activation of preview planes
560 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
561 XGUI_Displayer* aDisp = aWorkshop->displayer();
562 aWorkshop->selectionActivate()->activateObjects(QIntList(), aDisp->displayedObjects(), false);
564 if (!aBodyIsVisualized) {
565 // We have to select a plane before any operation
566 myPreviewPlanes->showPreviewPlanes(myWorkshop);
567 mySizeOfViewWidget->setVisible(true);
570 mySizeOfViewWidget->setVisible(false);
573 void PartSet_WidgetSketchLabel::showEvent(QShowEvent* theEvent)
575 if (mySizeOfViewWidget->isVisible()) {
576 DocumentPtr aDoc = feature()->document();
577 DocumentPtr aModDoc = ModelAPI_Session::get()->moduleDocument();
578 if (aModDoc == aDoc) {
579 myPartSetMessage->move(mapToGlobal(geometry().bottomLeft()));
580 myPartSetMessage->show();
582 mySizeMessage->move(mySizeOfView->mapToGlobal(mySizeOfView->geometry().center()));
583 mySizeMessage->show();
588 void PartSet_WidgetSketchLabel::deactivate()
590 ModuleBase_WidgetValidated::deactivate();
591 bool aHidePreview = myPreviewPlanes->isPreviewDisplayed();
592 myPreviewPlanes->erasePreviewPlanes(myWorkshop);
595 myWorkshop->viewer()->update();
597 if (myOpenTransaction) {
598 SessionPtr aMgr = ModelAPI_Session::get();
599 aMgr->finishOperation();
600 myOpenTransaction = false;
604 void PartSet_WidgetSketchLabel::selectionModes(int& theModuleSelectionModes, QIntList& theModes)
606 theModuleSelectionModes = -1;
607 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
609 theModes << TopAbs_FACE;
612 void PartSet_WidgetSketchLabel::selectionFilters(QIntList& theModuleSelectionFilters,
613 SelectMgr_ListOfFilter& theSelectionFilters)
615 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
618 return ModuleBase_WidgetValidated::selectionFilters(theModuleSelectionFilters,
619 theSelectionFilters);
622 std::shared_ptr<GeomAPI_Dir>
623 PartSet_WidgetSketchLabel::setSketchPlane(const TopoDS_Shape& theShape)
625 if (theShape.IsNull())
626 return std::shared_ptr<GeomAPI_Dir>();
628 // get selected shape
629 std::shared_ptr<GeomAPI_Shape> aGShape(new GeomAPI_Shape);
630 aGShape->setImpl(new TopoDS_Shape(theShape));
632 // get plane parameters
633 std::shared_ptr<GeomAPI_Face> aFace(new GeomAPI_Face(aGShape));
634 std::shared_ptr<GeomAPI_Pln> aPlane = aFace->getPlane();
636 return std::shared_ptr<GeomAPI_Dir>();
637 return setSketchPlane(aPlane);
640 std::shared_ptr<GeomAPI_Dir>
641 PartSet_WidgetSketchLabel::setSketchPlane(std::shared_ptr<GeomAPI_Pln> thePlane)
643 // set plane parameters to feature
644 std::shared_ptr<ModelAPI_Data> aData = feature()->data();
645 double anA, aB, aC, aD;
646 thePlane->coefficients(anA, aB, aC, aD);
648 // calculate attributes of the sketch
649 std::shared_ptr<GeomAPI_Dir> aNormDir(new GeomAPI_Dir(anA, aB, aC));
650 std::shared_ptr<GeomAPI_XYZ> aCoords = aNormDir->xyz();
651 std::shared_ptr<GeomAPI_XYZ> aZero(new GeomAPI_XYZ(0, 0, 0));
652 aCoords = aCoords->multiplied(-aD * aCoords->distance(aZero));
653 std::shared_ptr<GeomAPI_Pnt> anOrigPnt(new GeomAPI_Pnt(aCoords));
654 // X axis is preferable to be dirX on the sketch
655 const double tol = Precision::Confusion();
656 bool isX = fabs(fabs(anA) - 1.0) < tol && fabs(aB) < tol && fabs(aC) < tol;
657 std::shared_ptr<GeomAPI_Dir> aTempDir(
658 isX ? new GeomAPI_Dir(0, 1, 0) : new GeomAPI_Dir(1, 0, 0));
659 std::shared_ptr<GeomAPI_Dir> aYDir(new GeomAPI_Dir(aNormDir->cross(aTempDir)));
660 std::shared_ptr<GeomAPI_Dir> aXDir(new GeomAPI_Dir(aYDir->cross(aNormDir)));
662 std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
663 aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
664 anOrigin->setValue(anOrigPnt);
665 std::shared_ptr<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
666 aData->attribute(SketchPlugin_Sketch::NORM_ID()));
667 aNormal->setValue(aNormDir);
668 std::shared_ptr<GeomDataAPI_Dir> aDirX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
669 aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
670 aDirX->setValue(aXDir);
671 std::shared_ptr<GeomAPI_Dir> aDir = thePlane->direction();
675 void PartSet_WidgetSketchLabel::onSetPlaneView()
677 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
679 std::shared_ptr<GeomAPI_Dir> aDirection = aPlane->direction();
680 gp_Dir aDir = aDirection->impl<gp_Dir>();
681 if (myViewInverted->isChecked())
683 myWorkshop->viewer()->setViewProjection(aDir.X(), aDir.Y(), aDir.Z(), 0.);
684 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
686 aModule->onViewTransformed();
691 //******************************************************
692 QList<std::shared_ptr<ModuleBase_ViewerPrs>> PartSet_WidgetSketchLabel::findCircularEdgesInPlane()
694 QList<std::shared_ptr<ModuleBase_ViewerPrs>> aResult;
695 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
696 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
697 QObjectPtrList aDispObjects = aDisplayer->displayedObjects();
699 std::shared_ptr<GeomAPI_Pln> aPlane = plane();
700 foreach(ObjectPtr aObj, aDispObjects) {
701 ResultPtr aResObj = std::dynamic_pointer_cast<ModelAPI_Result>(aObj);
703 GeomShapePtr aShape = aResObj->shape();
705 GeomAPI_ShapeExplorer aExplorer(aShape, GeomAPI_Shape::EDGE);
706 for(; aExplorer.more(); aExplorer.next()) {
707 GeomShapePtr aEdgeShape = aExplorer.current();
708 GeomAPI_Edge anEdge(aEdgeShape);
709 if ((anEdge.isCircle() || anEdge.isArc() || anEdge.isEllipse()) &&
710 anEdge.isInPlane(aPlane)) {
711 bool isContains = false;
712 // Check that edge is not used.
713 // It is possible that the same edge will be taken from different faces
714 foreach(std::shared_ptr<ModuleBase_ViewerPrs> aPrs, aResult) {
715 GeomAPI_Edge aUsedEdge(aPrs->shape());
716 if (aUsedEdge.isEqual(aEdgeShape)) {
722 std::shared_ptr<ModuleBase_ViewerPrs>
723 aPrs(new ModuleBase_ViewerPrs(aResObj, aEdgeShape));
724 aResult.append(aPrs);
734 //******************************************************
735 void PartSet_WidgetSketchLabel::onChangePlane()
737 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
739 mySizeOfViewWidget->setVisible(false);
740 myRemoveExternal->setVisible(true);
741 myStackWidget->setCurrentIndex(0);
743 bool aBodyIsVisualized = myPreviewPlanes->hasVisualizedBodies(myWorkshop);
745 if (!aBodyIsVisualized) {
746 // We have to select a plane before any operation
747 myPreviewPlanes->showPreviewPlanes(myWorkshop);
750 CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
751 PartSet_Tools::nullifySketchPlane(aSketch);
753 Handle(SelectMgr_Filter) aFilter = aModule->selectionFilter(SF_SketchPlaneFilter);
754 if (!aFilter.IsNull()) {
755 std::shared_ptr<GeomAPI_Pln> aPln;
756 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(aPln);
758 XGUI_Workshop* aWorkshop = aModule->getWorkshop();
760 aWorkshop->selectionActivate()->updateSelectionFilters();
761 aWorkshop->selectionActivate()->updateSelectionModes();
763 SessionPtr aMgr = ModelAPI_Session::get();
764 aMgr->startOperation("Change Sketch plane");
765 myOpenTransaction = true;
766 myWorkshop->viewer()->update();
770 void PartSet_WidgetSketchLabel::setShowPointsState(bool theState)
772 bool aBlock = myShowPoints->blockSignals(true);
773 myShowPoints->setChecked(theState);
774 myShowPoints->blockSignals(aBlock);
777 bool PartSet_WidgetSketchLabel::restoreValueCustom()
779 if (myFeature.get()) {
780 CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
781 if (aSketch.get() && (aSketch->numberOfSubs() > 0)) {
782 AttributeStringPtr aDOFStr = aSketch->string("SolverDOF");
784 QString aVal(aDOFStr->value().c_str());
785 if (aVal.contains('=')) {
786 // to support old data
787 aVal = aVal.right(aVal.length() - aVal.lastIndexOf('='));
789 int aDoF = aVal.toInt();
791 myDoFLabel->setText(tr("Sketch is fully fixed (DoF = 0)"));
793 myDoFLabel->setText(tr("DoF (degrees of freedom) = ") + aVal);
798 myDoFLabel->setText("");