1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "PartSet_SketcherMgr.h"
23 #include "PartSet_Filters.h"
24 #include "PartSet_SketcherReentrantMgr.h"
25 #include "PartSet_Module.h"
26 #include "PartSet_MouseProcessor.h"
27 #include "PartSet_Tools.h"
28 #include "PartSet_WidgetSketchLabel.h"
29 #include "PartSet_WidgetEditor.h"
30 #include "PartSet_ResultSketchPrs.h"
31 #include "PartSet_ExternalPointsMgr.h"
32 #include "PartSet_PreviewSketchPlane.h"
34 #include <XGUI_ModuleConnector.h>
35 #include <XGUI_Displayer.h>
36 #include <XGUI_Workshop.h>
37 #include <XGUI_ContextMenuMgr.h>
38 #include <XGUI_Selection.h>
39 #include <XGUI_SelectionActivate.h>
40 #include <XGUI_SelectionMgr.h>
41 #include <XGUI_ModuleConnector.h>
42 #include <XGUI_PropertyPanel.h>
43 #include <XGUI_ViewerProxy.h>
44 #include <XGUI_OperationMgr.h>
45 #include <XGUI_ErrorMgr.h>
46 #include <XGUI_Tools.h>
48 #include <ModuleBase_IPropertyPanel.h>
49 #include <ModuleBase_ISelection.h>
50 #include <ModuleBase_IViewer.h>
51 #include <ModuleBase_IWorkshop.h>
52 #include <ModuleBase_IViewWindow.h>
53 #include <ModuleBase_ModelWidget.h>
54 #include <ModuleBase_Operation.h>
55 #include <ModuleBase_OperationFeature.h>
56 #include <ModuleBase_Operation.h>
57 #include <ModuleBase_WidgetEditor.h>
58 #include <ModuleBase_ViewerPrs.h>
59 #include <ModuleBase_Tools.h>
60 #include <ModuleBase_ResultPrs.h>
61 #include <ModuleBase_ViewerFilters.h>
63 #include <GeomDataAPI_Point2D.h>
65 #include <Events_Loop.h>
67 #include <SketchPlugin_Line.h>
68 #include <SketchPlugin_Sketch.h>
69 #include <SketchPlugin_Point.h>
70 #include <SketchPlugin_Arc.h>
71 #include <SketchPlugin_Circle.h>
72 #include <SketchPlugin_ConstraintLength.h>
73 #include <SketchPlugin_ConstraintDistance.h>
74 #include <SketchPlugin_ConstraintParallel.h>
75 #include <SketchPlugin_ConstraintPerpendicular.h>
76 #include <SketchPlugin_ConstraintRadius.h>
77 #include <SketchPlugin_ConstraintRigid.h>
78 #include <SketchPlugin_ConstraintHorizontal.h>
79 #include <SketchPlugin_ConstraintVertical.h>
80 #include <SketchPlugin_ConstraintEqual.h>
81 #include <SketchPlugin_ConstraintTangent.h>
82 #include <SketchPlugin_ConstraintCoincidence.h>
83 #include <SketchPlugin_Fillet.h>
84 #include <SketchPlugin_ConstraintMirror.h>
85 #include <SketchPlugin_ConstraintAngle.h>
86 #include <SketchPlugin_ConstraintCollinear.h>
87 #include <SketchPlugin_ConstraintMiddle.h>
88 #include <SketchPlugin_MultiRotation.h>
89 #include <SketchPlugin_MultiTranslation.h>
90 #include <SketchPlugin_IntersectionPoint.h>
91 #include <SketchPlugin_Projection.h>
92 #include <SketchPlugin_ConstraintDistanceAlongDir.h>
93 #include <SketchPlugin_ConstraintDistanceHorizontal.h>
94 #include <SketchPlugin_ConstraintDistanceVertical.h>
96 #include <SketcherPrs_Tools.h>
98 #include <SelectMgr_IndexedMapOfOwner.hxx>
99 #include <StdSelect_BRepOwner.hxx>
101 //#include <AIS_DimensionSelectionMode.hxx>
102 #include <AIS_Shape.hxx>
103 #include <AIS_Dimension.hxx>
105 #include <ModelAPI_Events.h>
106 #include <ModelAPI_Session.h>
107 #include <ModelAPI_AttributeString.h>
109 #include <ModelAPI_Validator.h>
110 #include <ModelAPI_Tools.h>
112 #include <QMouseEvent>
113 #include <QApplication>
115 #include <QMessageBox>
116 #include <QMainWindow>
118 //#define DEBUG_DO_NOT_BY_ENTER
119 //#define DEBUG_SKETCHER_ENTITIES
120 //#define DEBUG_SKETCH_ENTITIES_ON_MOVE
122 //#define DEBUG_CURSOR
124 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
125 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge,
126 /// put the function result as is to the list of results.
127 /// \param theOwner a viewer selected owner
128 /// \param theFeature a feature, where the attribute is searched
129 /// \param theSketch a current sketch
130 /// \param theSelectedAttribute an output list of attributes
131 /// \param theSelectedResults an output list of edge results
132 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
133 const FeaturePtr& theFeature, const FeaturePtr& theSketch,
134 const ResultPtr& theResult,
135 std::set<AttributePtr>& theSelectedAttributes,
136 std::set<ResultPtr>& theSelectedResults,
137 TopTools_MapOfShape& theShapes)
139 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
140 if (aBRepOwner.IsNull())
142 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
143 aBRepOwner->Selectable());
144 if (aBRepOwner->HasShape()) {
145 const TopoDS_Shape& aShape = aBRepOwner->Shape();
146 theShapes.Add(aShape);
147 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
148 if (aShapeType == TopAbs_VERTEX) {
149 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
151 if (aPntAttr.get() != NULL)
152 theSelectedAttributes.insert(aPntAttr);
154 else if (aShapeType == TopAbs_EDGE &&
155 theSelectedResults.find(theResult) == theSelectedResults.end()) {
156 theSelectedResults.insert(theResult);
161 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
162 : QObject(theModule), myModule(theModule), myIsEditLaunching(false), myIsDragging(false),
163 myDragDone(false), myIsMouseOverWindow(false),
164 myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
165 myIsPopupMenuActive(false), myExternalPointsMgr(0)
167 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
168 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
170 myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
172 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
173 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
175 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
176 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
178 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
179 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
181 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
182 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
184 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
185 XGUI_Workshop* aWorkshop = aConnector->workshop();
186 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
188 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
189 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
190 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
192 mySketchPlane = new PartSet_PreviewSketchPlane();
194 registerSelectionFilter(SF_SketchCirclePointFilter, new PartSet_CirclePointFilter(anIWorkshop));
195 registerSelectionFilter(SF_SketchPlaneFilter, new ModuleBase_ShapeInPlaneFilter());
198 PartSet_SketcherMgr::~PartSet_SketcherMgr()
202 void PartSet_SketcherMgr::onEnterViewPort()
204 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
205 // created feature because it should be done in onMouseMove(). Some widgets watch
206 // the mouse move and use the cursor position to update own values. If the presentaion is
207 // redisplayed before this update, the feature presentation jumps from reset value to current.
208 myIsMouseOverWindow = true;
210 #ifdef DEBUG_DO_NOT_BY_ENTER
214 if (canChangeCursor(getCurrentOperation())) {
215 QCursor* aCurrentCursor = QApplication::overrideCursor();
216 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
217 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
219 qDebug("onEnterViewPort() : Qt::CrossCursor");
224 if (!isNestedCreateOperation(getCurrentOperation(), activeSketch()))
227 operationMgr()->onValidateOperation();
229 // we need change displayed state of the current operation feature
230 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
231 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
232 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
233 // presentation becomes valid and redisplay happens
234 //ModuleBase_Operation* aOperation = getCurrentOperation();
235 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
236 (getCurrentOperation());
238 FeaturePtr aFeature = aFOperation->feature();
239 if (aFeature.get() && aFeature->data()->isValid()) {
240 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
245 void PartSet_SketcherMgr::onLeaveViewPort()
247 myIsMouseOverViewProcessed = false;
248 myIsMouseOverWindow = false;
250 #ifdef DEBUG_DO_NOT_BY_ENTER
254 if (canChangeCursor(getCurrentOperation())) {
255 QApplication::restoreOverrideCursor();
257 qDebug("onLeaveViewPort() : None");
261 if (!isNestedCreateOperation(getCurrentOperation(), activeSketch()))
264 // the method should be performed if the popup menu is called,
265 // the reset of the current widget should not happen
266 if (myIsPopupMenuActive)
269 // it is important to validate operation here only if sketch entity create operation is active
270 // because at this operation we reacts to the mouse leave/enter view port
271 operationMgr()->onValidateOperation();
273 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
274 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
275 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
276 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
277 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
278 // obtained after reset value
279 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
280 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
282 anActiveWidget->reset();
284 // hides the presentation of the current operation feature
285 // the feature is to be erased here, but it is correct to call canDisplayObject because
286 // there can be additional check (e.g. editor widget in distance constraint)
287 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
288 (getCurrentOperation());
290 FeaturePtr aFeature = aFOperation->feature();
291 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
293 // we should update viewer after the presentation are hidden in the viewer
294 // otherwise the reset presentation(line) appears in the viewer(by quick move from viewer to PP)
295 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
299 //Temporary commented as we do not modify values in property panel
300 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
302 if (!isNestedEditOperation(getCurrentOperation(), myModule->sketchMgr()->activeSketch()) ||
303 myModule->sketchReentranceMgr()->isInternalEditActive())
305 // it is necessary to save current selection in order to restore it after the values are modifed
306 storeSelection(ST_SelectAndHighlightType);
308 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
309 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
310 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
311 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
314 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
316 if (!isNestedEditOperation(getCurrentOperation(), myModule->sketchMgr()->activeSketch()) ||
317 myModule->sketchReentranceMgr()->isInternalEditActive()) {
318 myModule->sketchReentranceMgr()->updateInternalEditActiveState();
321 // it is necessary to restore current selection in order to restore it after values are modified
323 myCurrentSelection.clear();
325 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
326 // viewer happens by deselect/select the modified objects. The flag should be restored after
327 // the selection processing. The update viewer should be also called.
328 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
329 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
330 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
331 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
332 aDisplayer->updateViewer();
336 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
338 // Clear dragging mode
339 myIsDragging = false;
341 if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
343 //get2dPoint(theWnd, theEvent, myClickedPoint);
344 if (!(theEvent->buttons() & Qt::LeftButton))
347 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
348 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
349 if (!aViewer->canDragByMouse())
352 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
353 (getCurrentOperation());
357 if (aFOperation->isEditOperation()) {
358 // If the current widget is a selector, do nothing, it processes the mouse press
359 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
360 if(anActiveWidget && anActiveWidget->isViewerSelector()) {
365 // Use only for sketch operations
366 if (myCurrentSketch) {
367 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
370 bool isSketcher = isSketchOperation(aFOperation);
371 bool isSketchOpe = isNestedSketchOperation(aFOperation);
373 // Avoid non-sketch operations
374 if ((!isSketchOpe) && (!isSketcher))
377 bool isEditing = aFOperation->isEditOperation();
379 // Ignore creation sketch operation
380 if ((!isSketcher) && (!isEditing))
383 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
384 // Remember highlighted objects for editing
385 ModuleBase_ISelection* aSelect = aWorkshop->selection();
387 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
388 storeSelection(aHasShift ? ST_SelectAndHighlightType : ST_HighlightType, myCurrentSelection);
390 if (myCurrentSelection.empty()) {
391 if (isSketchOpe && (!isSketcher))
392 // commit previous operation
393 if (!aFOperation->commit())
394 aFOperation->abort();
397 // Init flyout point for radius rotation
398 FeaturePtr aFeature = myCurrentSelection.begin().key();
400 get2dPoint(theWnd, theEvent, myCurrentPoint);
405 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
407 if (aFeature.get() != NULL) {
408 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
409 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
410 if (aSPFeature.get() &&
411 (aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID() ||
412 aSPFeature->getKind() == SketchPlugin_ConstraintAngle::ID())) {
413 DataPtr aData = aSPFeature->data();
414 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
415 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
416 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
417 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
420 } else if (isSketchOpe && isEditing) {
421 // If selected another object commit current result
422 bool aPrevLaunchingState = myIsEditLaunching;
423 /// store editing state for Edit operation in order to do not clear highlight by restart
424 /// of edit operation.
425 /// Internal edit should not be stored as editing operation as the result will be a
426 /// creation operation, where previous selection should not be used(and will be cleared)
427 myIsEditLaunching = !myModule->sketchReentranceMgr()->isInternalEditActive();
428 aFOperation->commit();
433 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
435 myIsEditLaunching = aPrevLaunchingState;
436 if (aFeature.get() != NULL) {
437 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
438 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
439 if (aSPFeature.get() &&
440 (aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID() ||
441 aSPFeature->getKind() == SketchPlugin_ConstraintAngle::ID())) {
442 DataPtr aData = aSPFeature->data();
443 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
444 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
445 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
446 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
453 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
455 bool aWasDragging = myIsDragging;
456 myIsDragging = false;
458 if (myModule->sketchReentranceMgr()->processMouseReleased(theWnd, theEvent))
461 // if mouse is pressed when it was over view and at release the mouse is out of view, do nothing
462 if (!myIsMouseOverViewProcessed)
465 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
466 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
467 if (!aViewer->canDragByMouse())
469 ModuleBase_Operation* aOp = getCurrentOperation();
471 if (isNestedSketchOperation(aOp)) {
472 // Only for sketcher operations
475 /// the previous selection is lost by mouse release in the viewer(Select method), but
476 /// it is still stored in myCurrentSelection. So, it is possible to restore selection
477 /// It is important for drag(edit with mouse) of sketch entities.
478 restoreSelection(myCurrentSelection);
479 myCurrentSelection.clear();
485 aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
487 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
488 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
490 aProcessor->mouseReleased(theWnd, theEvent);
493 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
495 #ifdef DEBUG_SKETCH_ENTITIES_ON_MOVE
496 CompositeFeaturePtr aSketch = activeSketch();
498 std::cout << "mouse move SKETCH FEATURES [" << aSketch->numberOfSubs() << "]:" << std::endl;
500 for (int i = 0, aNbSubs = aSketch->numberOfSubs(); i < aNbSubs; i++) {
501 //std::cout << getFeatureInfo(aSketch->subFeature(i), false) << std::endl;
502 anInfo.append(ModuleBase_Tools::objectInfo(aSketch->subFeature(i)));
504 QString anInfoStr = anInfo.join("\n");
505 qDebug(QString("%1").arg(anInfo.size()).arg(anInfoStr).toStdString().c_str());
509 if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
512 if (isNestedCreateOperation(getCurrentOperation(), activeSketch())) {
513 // 1. perform the widget mouse move functionality and display the presentation
514 // the mouse move should be processed in the widget, if it can in order to visualize correct
515 // presentation. These widgets correct the feature attribute according to the mouse position
516 ModuleBase_ModelWidget* anActiveWidget = myModule->activeWidget();
517 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
519 aProcessor->mouseMoved(theWnd, theEvent);
520 if (!myIsMouseOverViewProcessed) {
521 myIsMouseOverViewProcessed = true;
523 // the feature is to be erased here, but it is correct to call canDisplayObject because
524 // there can be additional check (e.g. editor widget in distance constraint)
525 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
526 (getCurrentOperation());
528 FeaturePtr aFeature = aFOperation->feature();
529 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
533 //myClickedPoint.clear();
536 // 1. the current selection is saved in the mouse press method in order to restore it after
538 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
539 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
540 // deselected). This flag should be restored in the slot, processed the mouse release signal.
542 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
543 if (!aCurrentOperation)
545 if (isSketchOperation(aCurrentOperation))
546 return; // No edit operation activated
548 Handle(V3d_View) aView = theWnd->v3dView();
549 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
551 get2dPoint(theWnd, theEvent, aMousePnt);
553 std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition = std::shared_ptr<GeomAPI_Pnt2d>(
554 new GeomAPI_Pnt2d(myCurrentPoint.myCurX, myCurrentPoint.myCurY));
555 std::shared_ptr<GeomAPI_Pnt2d> aCurrentPosition = std::shared_ptr<GeomAPI_Pnt2d>(
556 new GeomAPI_Pnt2d(aMousePnt.myCurX, aMousePnt.myCurY));
558 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
559 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
560 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
561 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
562 // viewer happens by deselect/select the modified objects. The flag should be restored after
563 // the selection processing. The update viewer should be also called.
564 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
566 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
567 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
568 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
569 aLast = myCurrentSelection.end();
570 // 4. the features and attributes modification(move)
571 bool isModified = false;
572 for (; anIt != aLast; anIt++) {
573 FeaturePtr aFeature = anIt.key();
575 std::set<AttributePtr> anAttributes = anIt.value().myAttributes;
576 // Process selection by attribute: the priority to the attribute
577 if (!anAttributes.empty()) {
578 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
579 anAttLast = anAttributes.end();
580 for (; anAttIt != anAttLast; anAttIt++) {
581 AttributePtr anAttr = *anAttIt;
582 if (anAttr.get() == NULL)
584 std::string aAttrId = anAttr->id();
585 DataPtr aData = aFeature->data();
586 if (aData->isValid()) {
587 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
588 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
589 if (aPoint.get() != NULL) {
590 bool isImmutable = aPoint->setImmutable(true);
592 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage = std::shared_ptr
593 <ModelAPI_ObjectMovedMessage>(new ModelAPI_ObjectMovedMessage(this));
594 aMessage->setMovedAttribute(aPoint);
595 aMessage->setOriginalPosition(anOriginalPosition);
596 aMessage->setCurrentPosition(aCurrentPosition);
597 Events_Loop::loop()->send(aMessage);
600 aPoint->setImmutable(isImmutable);
605 // Process selection by feature
606 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
607 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
608 if (aSketchFeature) {
609 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage = std::shared_ptr
610 <ModelAPI_ObjectMovedMessage>(new ModelAPI_ObjectMovedMessage(this));
611 aMessage->setMovedObject(aFeature);
612 aMessage->setOriginalPosition(anOriginalPosition);
613 aMessage->setCurrentPosition(aCurrentPosition);
614 Events_Loop::loop()->send(aMessage);
619 // the modified state of the current operation should be updated if there are features, which
622 aCurrentOperation->onValuesChanged();
623 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
625 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
627 // 5. it is necessary to save current selection in order to restore it after the features moving
628 restoreSelection(myCurrentSelection);
629 // 6. restore the update viewer flag and call this update
630 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
631 aDisplayer->updateViewer();
634 myCurrentPoint = aMousePnt;
638 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
640 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
641 (getCurrentOperation());
642 if (aFOperation && aFOperation->isEditOperation()) {
643 std::string aId = aFOperation->id().toStdString();
644 if (isDistanceOperation(aFOperation))
646 // Activate dimension value editing on double click
647 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
648 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
649 // Find corresponded widget to activate value editing
650 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
651 if (aWgt->attributeID() == SketchPlugin_Constraint::VALUE() ||
652 aWgt->attributeID() == SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID()) {
653 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
655 anEditor->showPopupEditor();
663 void PartSet_SketcherMgr::onApplicationStarted()
665 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
666 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
667 XGUI_Workshop* aWorkshop = aConnector->workshop();
668 PartSet_SketcherReentrantMgr* aReentranceMgr = myModule->sketchReentranceMgr();
670 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
671 if (aPropertyPanel) {
672 //connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
673 // this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
675 connect(aPropertyPanel, SIGNAL(noMoreWidgets(const std::string&)),
676 aReentranceMgr, SLOT(onNoMoreWidgets(const std::string&)));
677 //connect(aPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
678 // aReentranceMgr, SLOT(onWidgetActivated()));
681 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
682 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
683 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
685 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
686 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
687 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
690 //void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
692 //if (!myClickedPoint.myIsInitialized)
695 //ModuleBase_Operation* aOperation = getCurrentOperation();
696 // the distance constraint feature should not use the clickedd point
697 // this is workaround in order to don't throw down the flyout point value,
698 // set by execute() method of these type of features
699 //if (isDistanceOperation(aOperation))
702 //PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
704 // aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
708 void PartSet_SketcherMgr::onBeforeContextMenu()
710 myIsPopupMenuActive = true;
713 void PartSet_SketcherMgr::onAfterContextMenu()
715 myIsPopupMenuActive = false;
718 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
721 Handle(V3d_View) aView = theWnd->v3dView();
722 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
724 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
725 thePoint.setValue(aX, anY);
728 void PartSet_SketcherMgr::launchEditing()
730 if (!myCurrentSelection.empty()) {
731 FeaturePtr aFeature = myCurrentSelection.begin().key();
732 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
733 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
735 if (!aSPFeature->isExternal())
736 myModule->editFeature(aSPFeature);
738 // need to edit a feature (Projection/IntersectionPoint),
739 // which produces current External feature
740 FeaturePtr aProducerFeature = PartSet_Tools::findRefsToMeFeature(aFeature,
741 SketchPlugin_Projection::ID());
742 if (!aProducerFeature.get())
743 aProducerFeature = PartSet_Tools::findRefsToMeFeature(aFeature,
744 SketchPlugin_IntersectionPoint::ID());
745 if (aProducerFeature.get())
746 myModule->editFeature(aProducerFeature);
752 bool PartSet_SketcherMgr::sketchSolverError()
754 bool anError = false;
755 CompositeFeaturePtr aSketch = activeSketch();
757 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
758 anError = !aAttributeString->value().empty();
763 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
766 if (!theFeature.get() || !theFeature->data()->isValid())
769 CompositeFeaturePtr aSketch = activeSketch();
770 if (aSketch.get() && aSketch == theFeature) {
771 std::string aSolverError = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR())->value();
772 anError = ModuleBase_Tools::translate(aSketch->getKind(), aSolverError);
777 void PartSet_SketcherMgr::clearClickedFlags()
779 //myClickedPoint.clear();
780 myCurrentPoint.clear();
783 const QStringList& PartSet_SketcherMgr::replicationsIdList()
785 static QStringList aReplicationIds;
786 if (aReplicationIds.size() == 0) {
787 aReplicationIds << SketchPlugin_ConstraintMirror::ID().c_str();
788 aReplicationIds << SketchPlugin_MultiRotation::ID().c_str();
789 aReplicationIds << SketchPlugin_MultiTranslation::ID().c_str();
791 return aReplicationIds;
794 const QStringList& PartSet_SketcherMgr::constraintsIdList()
796 static QStringList aConstraintIds;
797 if (aConstraintIds.size() == 0) {
798 aConstraintIds << SketchPlugin_ConstraintLength::ID().c_str();
799 aConstraintIds << SketchPlugin_ConstraintDistance::ID().c_str();
800 aConstraintIds << SketchPlugin_ConstraintRigid::ID().c_str();
801 aConstraintIds << SketchPlugin_ConstraintRadius::ID().c_str();
802 aConstraintIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
803 aConstraintIds << SketchPlugin_ConstraintParallel::ID().c_str();
804 aConstraintIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
805 aConstraintIds << SketchPlugin_ConstraintVertical::ID().c_str();
806 aConstraintIds << SketchPlugin_ConstraintEqual::ID().c_str();
807 aConstraintIds << SketchPlugin_ConstraintTangent::ID().c_str();
808 aConstraintIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
809 aConstraintIds << SketchPlugin_ConstraintAngle::ID().c_str();
810 aConstraintIds << SketchPlugin_ConstraintCollinear::ID().c_str();
811 aConstraintIds << SketchPlugin_ConstraintMiddle::ID().c_str();
812 aConstraintIds << SketchPlugin_ConstraintMirror::ID().c_str();
813 aConstraintIds << SketchPlugin_MultiTranslation::ID().c_str();
814 aConstraintIds << SketchPlugin_MultiRotation::ID().c_str();
815 aConstraintIds << SketchPlugin_ConstraintDistanceAlongDir::ID().c_str();
816 aConstraintIds << SketchPlugin_ConstraintDistanceHorizontal::ID().c_str();
817 aConstraintIds << SketchPlugin_ConstraintDistanceVertical::ID().c_str();
819 return aConstraintIds;
822 void PartSet_SketcherMgr::sketchSelectionModes(const CompositeFeaturePtr& theSketch,
825 if (!theSketch.get() || !PartSet_Tools::sketchPlane(theSketch).get())
828 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
829 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
830 theModes.append(SketcherPrs_Tools::Sel_Constraint);
831 theModes.append(TopAbs_VERTEX);
832 theModes.append(TopAbs_EDGE);
835 Handle(AIS_InteractiveObject) PartSet_SketcherMgr::createPresentation(const ResultPtr& theResult)
837 Handle(AIS_InteractiveObject) aPrs;
839 FeaturePtr aFeature = ModelAPI_Feature::feature(theResult);
840 if (aFeature.get() && aFeature->getKind() == SketchPlugin_Sketch::ID()) {
841 aPrs = new PartSet_ResultSketchPrs(theResult);
846 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
848 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
851 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation) const
853 bool aNestedSketch = false;
855 FeaturePtr anActiveSketch = activeSketch();
856 if (anActiveSketch.get() && theOperation) {
857 ModuleBase_Operation* aSketchOperation = operationMgr()->findOperation(
858 anActiveSketch->getKind().c_str());
859 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
861 if (aSketchOperation && aFOperation) {
862 FeaturePtr aFeature = aFOperation->feature();
863 if (aFeature.get()) {
864 QStringList aGrantedOpIds = aSketchOperation->grantedOperationIds();
865 aNestedSketch = aGrantedOpIds.contains(aFeature->getKind().c_str());
869 return aNestedSketch;
872 bool PartSet_SketcherMgr::isNestedSketchFeature(const QString& theFeatureKind) const
874 bool aNestedSketch = false;
876 FeaturePtr anActiveSketch = activeSketch();
877 if (anActiveSketch.get()) {
878 ModuleBase_Operation* aSketchOperation = operationMgr()->findOperation(
879 anActiveSketch->getKind().c_str());
880 if (aSketchOperation) {
881 QStringList aGrantedOpIds = aSketchOperation->grantedOperationIds();
882 aNestedSketch = aGrantedOpIds.contains(theFeatureKind);
885 return aNestedSketch;
888 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation,
889 const CompositeFeaturePtr& theSketch) const
891 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
893 return aFOperation && !aFOperation->isEditOperation() &&
894 isNestedSketchOperation(aFOperation);
897 bool PartSet_SketcherMgr::isNestedEditOperation(ModuleBase_Operation* theOperation,
898 const CompositeFeaturePtr& theSketch) const
900 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
902 return aFOperation && aFOperation->isEditOperation() &&
903 isNestedSketchOperation(aFOperation);
906 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
908 return (theId == SketchPlugin_Line::ID()) ||
909 (theId == SketchPlugin_Point::ID()) ||
910 (theId == SketchPlugin_Arc::ID()) ||
911 (theId == SketchPlugin_Circle::ID());
914 bool PartSet_SketcherMgr::isExternalFeature(const FeaturePtr& theFeature)
916 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
917 std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
918 return aSPFeature.get() && aSPFeature->isExternal();
921 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
923 std::string anId = theOperation ? theOperation->id().toStdString() : "";
925 return isDistanceKind(anId);
928 bool PartSet_SketcherMgr::isDistanceKind(std::string& theKind)
930 return (theKind == SketchPlugin_ConstraintLength::ID()) ||
931 (theKind == SketchPlugin_ConstraintDistance::ID()) ||
932 (theKind == SketchPlugin_ConstraintRadius::ID()) ||
933 (theKind == SketchPlugin_ConstraintAngle::ID()) ||
934 (theKind == SketchPlugin_ConstraintDistanceHorizontal::ID()) ||
935 (theKind == SketchPlugin_ConstraintDistanceVertical::ID()) ||
936 (theKind == SketchPlugin_ConstraintDistanceAlongDir::ID());
939 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
941 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
942 (getCurrentOperation());
946 myModule->onViewTransformed();
948 // Display all sketcher sub-Objects
949 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
950 double aSizeOfView = 0;
951 std::shared_ptr<GeomAPI_Pnt> aCentralPoint;
952 if (aFOperation->isEditOperation() &&
953 mySketchPlane->getDefaultSizeOfView(myCurrentSketch, aSizeOfView, aCentralPoint)) {
954 mySketchPlane->setSizeOfView(aSizeOfView, true, aCentralPoint);
957 mySketchPlane->createSketchPlane(myCurrentSketch, myModule->workshop());
958 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
960 // Hide sketcher result
961 std::list<ResultPtr> aResults = myCurrentSketch->results();
962 std::list<ResultPtr>::const_iterator aIt;
963 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
964 (*aIt)->setDisplayed(false);
966 myCurrentSketch->setDisplayed(false);
968 // Remove invalid sketch entities
969 std::set<FeaturePtr> anInvalidFeatures;
970 ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
971 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
972 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
973 if (aFeature.get()) {
974 if (!aFactory->validate(aFeature))
975 anInvalidFeatures.insert(aFeature);
978 if (!anInvalidFeatures.empty()) {
979 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
980 ModelAPI_Tools::findAllReferences(anInvalidFeatures, aReferences, false);
982 std::set<FeaturePtr>::const_iterator anIt = anInvalidFeatures.begin(),
983 aLast = anInvalidFeatures.end();
984 // separate features to references to parameter features and references to others
985 QStringList anInvalidFeatureNames;
986 for (; anIt != aLast; anIt++) {
987 FeaturePtr aFeature = *anIt;
989 anInvalidFeatureNames.append(aFeature->name().c_str());
991 std::string aPrefixInfo = QString("Invalid features of the sketch will be deleted: %1.\n\n").
992 arg(anInvalidFeatureNames.join(", ")).toStdString().c_str();
993 std::set<FeaturePtr> aFeatureRefsToDelete;
994 if (ModuleBase_Tools::askToDelete(anInvalidFeatures, aReferences, aConnector->desktop(),
995 aFeatureRefsToDelete, aPrefixInfo)) {
996 if (!aFeatureRefsToDelete.empty())
997 anInvalidFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
998 ModelAPI_Tools::removeFeatures(anInvalidFeatures, true);
999 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
1000 // TODO: call the next method in the XGUI_OperationMgr::onOperationStarted().
1001 workshop()->errorMgr()->updateAcceptAllAction(myCurrentSketch);
1005 // update state of overconstraint listener should be done before sketch features/results
1006 // display (as the display will ask custom color from the listener)
1007 myModule->overconstraintListener()->setActive(true);
1008 // Display sketcher objects
1010 Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1011 const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
1012 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1013 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1014 #ifdef DEBUG_SKETCHER_ENTITIES
1015 anInfo.append(ModuleBase_Tools::objectInfo(aFeature));
1017 std::list<ResultPtr> aResults = aFeature->results();
1018 std::list<ResultPtr>::const_iterator aIt;
1019 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1020 if ((*aIt)->isDisplayed())
1021 // Display object if it was created outside of GUI
1022 aECreator->sendUpdated((*aIt), EVENT_DISP);
1024 (*aIt)->setDisplayed(true);
1026 if (aFeature->isDisplayed())
1027 aECreator->sendUpdated(aFeature, EVENT_DISP);
1029 aFeature->setDisplayed(true);
1031 #ifdef DEBUG_SKETCHER_ENTITIES
1032 QString anInfoStr = anInfo.join(";\t");
1033 qDebug(QString("startSketch: %1, %2").arg(anInfo.size()).arg(anInfoStr).toStdString().c_str());
1036 bool aHasPlane = false;
1037 std::shared_ptr<GeomAPI_Pln> aPln;
1038 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
1039 Handle(SelectMgr_Filter) aFilter = myModule->selectionFilter(SF_SketchPlaneFilter);
1040 if (!aFilter.IsNull())
1041 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(aPln);
1043 workshop()->selectionActivate()->updateSelectionFilters();
1044 workshop()->selectionActivate()->updateSelectionModes();
1046 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1048 myExternalPointsMgr = new PartSet_ExternalPointsMgr(myModule->workshop(), myCurrentSketch);
1051 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
1053 myIsMouseOverWindow = false;
1054 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
1055 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
1056 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
1058 if (myExternalPointsMgr) {
1059 delete myExternalPointsMgr;
1060 myExternalPointsMgr = 0;
1063 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
1065 DataPtr aData = myCurrentSketch->data();
1066 if (!aData->isValid()) {
1067 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1068 // The sketch was aborted
1069 myCurrentSketch = CompositeFeaturePtr();
1070 mySketchPlane->eraseSketchPlane(myModule->workshop());
1072 // Erase all sketcher objects
1073 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1074 foreach (ObjectPtr aObj, aObjects) {
1075 DataPtr aObjData = aObj->data();
1076 if (!aObjData->isValid())
1077 aObj->setDisplayed(false);
1081 // Hide all sketcher sub-Objects
1082 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1083 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1084 std::list<ResultPtr> aResults = aFeature->results();
1085 std::list<ResultPtr>::const_iterator aIt;
1086 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1087 (*aIt)->setDisplayed(false);
1089 aFeature->setDisplayed(false);
1091 // Display sketcher result
1092 std::list<ResultPtr> aResults = myCurrentSketch->results();
1093 std::list<ResultPtr>::const_iterator aIt;
1094 Events_Loop* aLoop = Events_Loop::loop();
1095 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1097 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1099 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1100 if (!aFOperation->isDisplayedOnStart(*aIt)) {
1101 (*aIt)->setDisplayed(true);
1102 // this display event is needed because sketch already may have "displayed" state,
1103 // but not displayed while it is still active (issue 613, abort of existing sketch)
1104 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
1107 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
1108 myCurrentSketch->setDisplayed(true);
1110 myCurrentSketch = CompositeFeaturePtr();
1111 mySketchPlane->eraseSketchPlane(myModule->workshop());
1113 Events_Loop::loop()->flush(aDispEvent);
1115 workshop()->selectionActivate()->updateSelectionFilters();
1116 workshop()->selectionActivate()->updateSelectionModes();
1119 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
1121 if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
1122 QCursor* aCurrentCursor = QApplication::overrideCursor();
1123 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
1124 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
1126 qDebug("startNestedSketch() : Qt::CrossCursor");
1132 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
1134 myIsMouseOverViewProcessed = true;
1135 operationMgr()->onValidateOperation();
1136 // when sketch nested operation is stopped the cursor should be restored unconditionally
1137 //if (canChangeCursor(theOperation)) {
1138 QApplication::restoreOverrideCursor();
1140 qDebug("stopNestedSketch() : None");
1143 /// improvement to deselect automatically all eventual selected objects, when
1144 // returning to the neutral point of the Sketcher
1145 bool isClearSelectionPossible = true;
1146 if (myIsEditLaunching) {
1147 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1150 FeaturePtr aFeature = aFOperation->feature();
1151 if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
1152 isClearSelectionPossible = false;
1156 if (isClearSelectionPossible)
1157 workshop()->selector()->clearSelection();
1160 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
1162 if (isNestedCreateOperation(theOperation, activeSketch())) {
1163 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1166 FeaturePtr aFeature = aFOperation->feature();
1167 // it is necessary to check the the feature data validity because
1168 // some kind of features are removed by an operation commit(the macro state of a feature)
1169 if (aFeature.get() && aFeature->data()->isValid()) {
1170 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
1176 bool PartSet_SketcherMgr::sketchSelectionFilter(const XGUI_SelectionFilterType theFilterType)
1178 return mySelectionFilterTypes.find(theFilterType) != mySelectionFilterTypes.end();
1181 void PartSet_SketcherMgr::registerSelectionFilter(const XGUI_SelectionFilterType theFilterType,
1182 const Handle(SelectMgr_Filter)& theFilter)
1184 mySelectionFilterTypes.insert(theFilterType);
1185 myModule->registerSelectionFilter(theFilterType, theFilter);
1188 bool PartSet_SketcherMgr::operationActivatedByPreselection()
1190 bool isOperationStopped = false;
1191 ModuleBase_Operation* anOperation = getCurrentOperation();
1192 if(anOperation && isNestedSketchOperation(anOperation)) {
1193 // Set final definitions if they are necessary
1194 //propertyPanelDefined(aOperation);
1195 /// Commit sketcher operations automatically
1196 /// distance operation are able to show popup editor to modify the distance value
1197 /// after entering the value, the operation should be committed/aborted(by Esc key)
1198 bool aCanCommitOperation = true;
1199 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1201 if (aFOperation && PartSet_SketcherMgr::isDistanceOperation(aFOperation)) {
1202 bool aValueAccepted = setDistanceValueByPreselection(anOperation, myModule->workshop(),
1203 aCanCommitOperation);
1204 if (!aValueAccepted)
1205 return isOperationStopped;
1208 if (aCanCommitOperation)
1209 isOperationStopped = anOperation->commit();
1211 anOperation->abort();
1212 isOperationStopped = true;
1215 return isOperationStopped;
1218 bool PartSet_SketcherMgr::canUndo() const
1220 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1223 bool PartSet_SketcherMgr::canRedo() const
1225 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1228 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1230 bool aCanErase = true;
1231 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1232 if (myCurrentSketch.get()) {
1233 return !isObjectOfSketch(theObject);
1238 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1240 bool aCanDisplay = true;
1242 bool aHasActiveSketch = activeSketch().get() != NULL;
1243 if (aHasActiveSketch) {
1244 // 1. the sketch feature should not be displayed during the sketch active operation
1245 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1246 // nested features can be visualized
1247 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1248 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1249 aCanDisplay = false;
1251 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1252 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1253 /// some sketch entities should be never shown, e.g. projection feature
1254 if (aSketchFeature.get())
1255 aCanDisplay = aSketchFeature->canBeDisplayed();
1257 else { // there are no an active sketch
1258 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1259 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1260 if (aFeature.get() != NULL) {
1261 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1262 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1263 if (aSketchFeature.get()) {
1264 aCanDisplay = false;
1269 // 3. the method should not filter the objects, which are not related to the current operation.
1270 // The object is filtered just if it is a current operation feature or this feature result
1272 bool isObjectFound = false;
1273 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1274 (getCurrentOperation());
1276 FeaturePtr aFeature = aFOperation->feature();
1277 if (aFeature.get()) {
1278 std::list<ResultPtr> aResults = aFeature->results();
1279 if (theObject == aFeature)
1280 isObjectFound = true;
1282 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1283 for (; anIt != aLast && !isObjectFound; anIt++) {
1284 isObjectFound = *anIt == theObject;
1289 if (isObjectFound) {
1290 // 4. For created nested feature operation do not display the created feature if
1291 // the mouse curstor leaves the OCC window.
1292 // The correction cases, which ignores this condition:
1293 // a. the property panel values modification
1294 // b. the popup menu activated
1295 // c. widget editor control
1296 #ifndef DEBUG_DO_NOT_BY_ENTER
1297 if (isNestedCreateOperation(getCurrentOperation(), activeSketch())) {
1298 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1299 ModuleBase_WidgetEditor* anEditorWdg =
1300 anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1301 // the active widget editor should not influence here. The presentation should be visible
1302 // always when this widget is active.
1303 if (!anEditorWdg && !myIsPopupMenuActive) {
1304 // during a nested create operation, the feature is redisplayed only
1305 // if the mouse over view
1306 // of there was a value modified in the property panel after the mouse left the view
1307 aCanDisplay = canDisplayCurrentCreatedFeature();
1314 // checks the sketcher constraints visibility according to active sketch check box states
1316 bool aProcessed = false;
1317 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1318 if (aFeature.get()) {
1319 bool aConstraintDisplayed = canDisplayConstraint(aFeature, PartSet_Tools::Any, aProcessed);
1321 aCanDisplay = aConstraintDisplayed;
1328 bool PartSet_SketcherMgr::canDisplayConstraint(const FeaturePtr& theFeature,
1329 const PartSet_Tools::ConstraintVisibleState& theState,
1330 bool& isProcessed) const
1332 bool aSwitchedOn = true;
1334 const QStringList& aConstrIds = constraintsIdList();
1336 std::string aKind = theFeature->getKind();
1337 if (aConstrIds.contains(QString(aKind.c_str()))) {
1338 bool isTypedConstraint = false;
1341 case PartSet_Tools::Dimensional: {
1342 bool isDistance = isDistanceKind(aKind);
1345 aSwitchedOn = myIsConstraintsShown[theState];
1349 case PartSet_Tools::Geometrical: {
1350 bool isGeometrical = !isDistanceKind(aKind);
1351 if (isGeometrical) {
1353 aSwitchedOn = myIsConstraintsShown[theState];
1357 case PartSet_Tools::Any: {
1359 bool isDistance = isDistanceKind(aKind);
1361 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Dimensional];
1363 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Geometrical];
1373 /*void PartSet_SketcherMgr::processHiddenObject(const std::list<ObjectPtr>& theObjects)
1375 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1376 (getCurrentOperation());
1377 if (aFOperation && myCurrentSketch.get()) {
1378 // find results of the current operation
1379 // these results should not be proposed to be deleted
1380 FeaturePtr anOperationFeature = aFOperation->feature();
1381 std::list<ResultPtr> anOperationResultList = anOperationFeature->results();
1382 std::set<ResultPtr> anOperationResults;
1383 std::list<ResultPtr>::const_iterator aRIt = anOperationResultList.begin(),
1384 aRLast = anOperationResultList.end();
1385 for (; aRIt != aRLast; aRIt++)
1386 anOperationResults.insert(*aRIt);
1388 std::set<FeaturePtr> anObjectsToBeDeleted;
1389 QStringList anObjectsToBeDeletedNames;
1390 std::list<ObjectPtr>::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1391 for (; anIt != aLast; anIt++) {
1392 ObjectPtr anObject = *anIt;
1393 bool aCanErase = true;
1394 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1395 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1396 // the result is found between current feature results
1397 if (anOperationResults.find(aResult) != anOperationResults.end())
1400 if (aResult.get()) {
1401 // Display sketcher objects
1402 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1403 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1404 std::list<ResultPtr> aResults = aFeature->results();
1405 std::list<ResultPtr>::const_iterator anIt;
1406 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1407 aCanErase = *anIt != aResult;
1412 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1413 if (aFeature.get() && anObjectsToBeDeleted.find(aFeature) == anObjectsToBeDeleted.end()) {
1414 anObjectsToBeDeleted.insert(aFeature);
1415 anObjectsToBeDeletedNames.append(aFeature->name().c_str());
1419 if (!anObjectsToBeDeleted.empty()) {
1420 QString aFeatureNames = anObjectsToBeDeletedNames.join(", ");
1421 QString aMessage = tr("The following features have incorrect presentation and \
1422 will be hidden: %1. Would you like to delete them?")
1423 .arg(aFeatureNames);
1424 int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Features hide"),
1425 aMessage, QMessageBox::Ok | QMessageBox::Cancel,
1426 QMessageBox::Cancel);
1427 if (anAnswer == QMessageBox::Ok) {
1428 QObjectPtrList anObjects;
1429 std::set<FeaturePtr>::const_iterator anIt = anObjectsToBeDeleted.begin(),
1430 aLast = anObjectsToBeDeleted.end();
1431 for (; anIt != aLast; anIt++)
1432 anObjects.append(*anIt);
1433 SessionPtr aMgr = ModelAPI_Session::get();
1434 DocumentPtr aDoc = aMgr->activeDocument();
1435 bool aIsOp = aMgr->isOperation();
1437 aMgr->startOperation();
1438 workshop()->deleteFeatures(anObjects);
1439 //static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
1440 //static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
1441 //Events_Loop::loop()->flush(aDeletedEvent);
1442 //Events_Loop::loop()->flush(aRedispEvent);
1445 aMgr->finishOperation();
1451 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1453 bool aCanDisplay = myIsMouseOverWindow;
1455 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1457 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1462 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1464 return isNestedCreateOperation(theOperation, activeSketch()) ||
1465 myModule->sketchReentranceMgr()->isInternalEditActive();
1468 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
1470 return myIsConstraintsShown;
1473 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1475 bool isFoundObject = false;
1477 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1478 if (anObjectFeature.get()) {
1479 int aSize = myCurrentSketch->numberOfSubs();
1480 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1481 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1482 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1485 return isFoundObject;
1488 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePlane)
1490 Handle(SelectMgr_Filter) aFilter = myModule->selectionFilter(SF_SketchPlaneFilter);
1491 if (!aFilter.IsNull())
1492 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(thePlane);
1494 workshop()->selectionActivate()->updateSelectionModes();
1497 bool PartSet_SketcherMgr::setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
1498 ModuleBase_IWorkshop* theWorkshop,
1499 bool& theCanCommitOperation)
1501 bool isValueAccepted = false;
1502 theCanCommitOperation = false;
1504 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1506 FeaturePtr aFeature = aFOperation->feature();
1507 // editor is shown only if all attribute references are filled by preseletion
1508 bool anAllRefAttrInitialized = true;
1510 std::list<AttributePtr> aRefAttrs = aFeature->data()->attributes(
1511 ModelAPI_AttributeRefAttr::typeId());
1512 std::list<AttributePtr>::const_iterator anIt = aRefAttrs.begin(), aLast = aRefAttrs.end();
1513 for (; anIt != aLast && anAllRefAttrInitialized; anIt++) {
1514 anAllRefAttrInitialized = (*anIt)->isInitialized();
1516 if (anAllRefAttrInitialized) {
1517 // Activate dimension value editing on double click
1518 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
1519 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
1520 // Find corresponded widget to activate value editing
1521 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
1522 if (aWgt->attributeID() == "ConstraintValue") {
1523 // the featue should be displayed in order to find the AIS text position,
1524 // the place where the editor will be shown
1525 aFeature->setDisplayed(true);
1526 /// the execute is necessary to perform in the feature compute for flyout position
1527 aFeature->execute();
1529 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1530 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1532 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
1534 int aX = 0, anY = 0;
1536 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(theWorkshop);
1537 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1538 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
1539 Handle(AIS_InteractiveObject) anAISIO;
1540 if (anAIS.get() != NULL) {
1541 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1543 if (anAIS.get() != NULL) {
1544 Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1546 if (!anAISIO.IsNull()) {
1547 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
1548 if (!aDim.IsNull()) {
1549 gp_Pnt aPosition = aDim->GetTextPosition();
1551 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
1552 Handle(V3d_View) aView = aViewer->activeView();
1554 aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
1556 QWidget* aViewPort = aViewer->activeViewPort();
1557 QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
1562 anEditor->setCursorPosition(aX, anY);
1563 isValueAccepted = anEditor->showPopupEditor(false);
1564 theCanCommitOperation = true;
1570 return isValueAccepted;
1573 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1574 const FeaturePtr& theSketch,
1575 ModuleBase_IWorkshop* theWorkshop,
1576 const FeatureToSelectionMap& theSelection,
1577 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1579 if (theFeature.get() == NULL)
1582 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1583 SelectionInfo anInfo = anIt.value();
1584 std::set<AttributePtr> aSelectedAttributes = anInfo.myAttributes;
1585 std::set<ResultPtr> aSelectedResults = anInfo.myResults;
1587 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1589 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1590 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1592 // 1. found the feature's owners. Check the AIS objects of the constructions
1593 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1594 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1595 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1597 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1598 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1599 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1600 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1601 if (!anOwner.IsNull())
1602 theOwnersToSelect.Add(anOwner);
1606 // 2. found the feature results's owners
1607 std::list<ResultPtr> aResults = theFeature->results();
1608 std::list<ResultPtr>::const_iterator aIt;
1610 bool isSameShape = false;
1611 if (aResults.size() > 0) {
1612 ResultPtr aFirstResult = theFeature->firstResult();
1613 if (aFirstResult.get() && aFirstResult->shape().get()) {
1614 TopoDS_Shape aFirstShape = aFirstResult->shape()->impl<TopoDS_Shape>();
1615 isSameShape = aFirstShape.IsEqual(anInfo.myFirstResultShape);
1618 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1619 ResultPtr aResult = *aIt;
1620 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1621 if (aAISObj.get() == NULL)
1623 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1625 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1626 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1627 bool aFoundLocalShape = false;
1628 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1629 Handle(StdSelect_BRepOwner) anOwner =
1630 Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1631 if ( anOwner.IsNull() || !anOwner->HasShape() || theOwnersToSelect.FindIndex(anOwner))
1633 const TopoDS_Shape& aShape = anOwner->Shape();
1634 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1635 if (aShapeType == TopAbs_VERTEX) {
1636 AttributePtr aPntAttr =
1637 PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1638 if (aPntAttr.get() != NULL &&
1639 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end())
1640 theOwnersToSelect.Add(anOwner);
1641 else if (isSameShape && anInfo.myLocalSelectedShapes.Contains(aShape)) {
1642 theOwnersToSelect.Add(anOwner);
1645 else if (aShapeType == TopAbs_EDGE) {
1646 if (isSameShape && anInfo.myLocalSelectedShapes.Contains(aShape)) {
1647 // try to restore local selection on Shape result
1648 // we can do this only if the shape was not changed
1649 theOwnersToSelect.Add(anOwner);
1650 aFoundLocalShape = true;
1655 if (!aFoundLocalShape) {
1656 // result owners are put in the list of selection only if local selected shapes were not
1658 if (aSelectedResults.find(aResult) != aSelectedResults.end()) {
1659 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1660 Handle(StdSelect_BRepOwner) anOwner =
1661 Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1662 if ( anOwner.IsNull() || !anOwner->HasShape() || theOwnersToSelect.FindIndex(anOwner))
1664 // select whole result
1665 theOwnersToSelect.Add(anOwner);
1672 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
1673 const bool isToConnect)
1675 //Temporary commented as we do not modify values in property panel
1677 //connect(theWidget, SIGNAL(beforeValuesChanged()),
1678 // this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1679 //connect(theWidget, SIGNAL(afterValuesChanged()),
1680 // this, SLOT(onAfterValuesChangedInPropertyPanel()));
1681 connect(theWidget, SIGNAL(afterValuesChanged()),
1682 myModule->sketchReentranceMgr(), SLOT(onAfterValuesChangedInPropertyPanel()));
1685 //disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1686 // this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1687 //disconnect(theWidget, SIGNAL(afterValuesChanged()),
1688 // this, SLOT(onAfterValuesChangedInPropertyPanel()));
1689 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1690 myModule->sketchReentranceMgr(), SLOT(onAfterValuesChangedInPropertyPanel()));
1694 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1696 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1697 (getCurrentOperation());
1699 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1700 isNestedSketchOperation(aFOperation) &&
1701 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1702 FeaturePtr aFeature = aFOperation->feature();
1703 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1708 void PartSet_SketcherMgr::customizePresentation(const ObjectPtr& theObject)
1710 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1711 (getCurrentOperation());
1712 if (aFOperation && (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1713 isNestedSketchOperation(aFOperation)))
1714 SketcherPrs_Tools::sendExpressionShownEvent(myIsConstraintsShown[PartSet_Tools::Expressions]);
1716 // update entities selection priorities
1717 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1718 if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
1719 // update priority for feature
1720 updateSelectionPriority(aFeature, aFeature);
1721 // update priority for results of the feature
1722 std::list<ResultPtr> aResults = aFeature->results();
1723 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLastIt = aResults.end();
1724 for (; anIt != aLastIt; anIt++)
1725 updateSelectionPriority(*anIt, aFeature);
1729 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1731 return myModule->workshop()->currentOperation();
1734 //**************************************************************
1735 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1737 ModuleBase_ModelWidget* aWidget = 0;
1738 ModuleBase_Operation* anOperation = getCurrentOperation();
1740 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1742 aWidget = aPanel->activeWidget();
1747 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1748 const bool isEditOperation,
1749 const bool isToDisplay,
1750 const bool isFlushRedisplay)
1752 #ifdef DEBUG_DO_NOT_BY_ENTER
1756 if (isEditOperation || !theFeature.get())
1759 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1760 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1762 // 1. change visibility of the object itself, here the presentable object is processed,
1763 // e.g. constraints features
1764 //FeaturePtr aFeature = aFOperation->feature();
1765 std::list<ResultPtr> aResults = theFeature->results();
1767 theFeature->setDisplayed(true);
1769 theFeature->setDisplayed(false);
1771 // change visibility of the object results, e.g. non-constraint features
1772 std::list<ResultPtr>::const_iterator aIt;
1773 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1775 (*aIt)->setDisplayed(true);
1778 (*aIt)->setDisplayed(false);
1781 if (isFlushRedisplay)
1782 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1785 void PartSet_SketcherMgr::storeSelection(const SelectionType theType,
1786 PartSet_SketcherMgr::FeatureToSelectionMap& theCurrentSelection)
1788 if (!myCurrentSketch.get())
1791 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1792 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1793 QList<ModuleBase_ViewerPrsPtr> aStoredPrs;
1795 if (theType == ST_HighlightType || theType == ST_SelectAndHighlightType)
1796 aStoredPrs = aSelect->getHighlighted();
1798 QList<FeaturePtr> aFeatureList;
1799 if (theType == ST_SelectAndHighlightType || theType == ST_SelectType) {
1800 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected(
1801 ModuleBase_ISelection::AllControls);
1802 aStoredPrs.append(aSelected);
1805 // 1. it is necessary to save current selection in order to restore it after the features moving
1806 theCurrentSelection.clear();
1808 QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = aStoredPrs.begin(),
1809 aLast = aStoredPrs.end();
1811 CompositeFeaturePtr aSketch = activeSketch();
1812 for (; anIt != aLast; anIt++) {
1813 ModuleBase_ViewerPrsPtr aPrs = *anIt;
1814 ObjectPtr anObject = aPrs->object();
1815 if (!anObject.get())
1818 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1819 FeaturePtr aFeature;
1821 aFeature = ModelAPI_Feature::feature(aResult);
1823 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1825 if (!aFeature.get())
1828 std::set<AttributePtr> aSelectedAttributes;
1829 std::set<ResultPtr> aSelectedResults;
1830 SelectionInfo anInfo;
1831 if (theCurrentSelection.find(aFeature) != theCurrentSelection.end())
1832 anInfo = theCurrentSelection.find(aFeature).value();
1834 TopoDS_Shape aFirstShape;
1835 ResultPtr aFirstResult = aFeature->firstResult();
1836 if (aFirstResult.get() && aFirstResult->shape().get())
1837 aFirstShape = aFirstResult->shape()->impl<TopoDS_Shape>();
1838 anInfo.myFirstResultShape = aFirstShape;
1839 Handle(SelectMgr_EntityOwner) anOwner = aPrs->owner();
1840 if (aResult.get()) {
1841 getAttributesOrResults(anOwner, aFeature, aSketch, aResult,
1842 anInfo.myAttributes, anInfo.myResults, anInfo.myLocalSelectedShapes);
1845 std::list<ResultPtr> aResults = aFeature->results();
1846 std::list<ResultPtr>::const_iterator aIt;
1847 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1848 ResultPtr aResult = *aIt;
1849 getAttributesOrResults(anOwner, aFeature, aSketch, aResult,
1850 anInfo.myAttributes, anInfo.myResults, anInfo.myLocalSelectedShapes);
1853 theCurrentSelection[aFeature] = anInfo;
1855 //qDebug(QString(" storeSelection: %1").arg(theCurrentSelection.size()).toStdString().c_str());
1858 void PartSet_SketcherMgr::restoreSelection(
1859 PartSet_SketcherMgr::FeatureToSelectionMap& theCurrentSelection)
1861 if (!myCurrentSketch.get())
1864 //qDebug(QString("restoreSelection: %1").arg(theCurrentSelection.size()).toStdString().c_str());
1865 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1866 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1867 FeatureToSelectionMap::const_iterator aSIt = theCurrentSelection.begin(),
1868 aSLast = theCurrentSelection.end();
1869 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1870 anOwnersToSelect.Clear();
1871 for (; aSIt != aSLast; aSIt++) {
1872 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, theCurrentSelection,
1875 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1878 void PartSet_SketcherMgr::onShowConstraintsToggle(int theType, bool theState)
1880 PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
1882 updateBySketchParameters(aType, theState);
1885 void PartSet_SketcherMgr::updateBySketchParameters(
1886 const PartSet_Tools::ConstraintVisibleState& theType,
1889 if (myCurrentSketch.get() == NULL)
1892 bool aPrevState = myIsConstraintsShown[theType];
1893 myIsConstraintsShown[theType] = theState;
1896 case PartSet_Tools::Geometrical:
1897 case PartSet_Tools::Dimensional: {
1898 if (aPrevState != theState) {
1899 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1900 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1901 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1902 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1903 bool aProcessed = false;
1904 bool aConstraintDisplayed = canDisplayConstraint(aSubFeature, theType, aProcessed);
1906 aSubFeature->setDisplayed(aConstraintDisplayed);
1908 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1912 case PartSet_Tools::Expressions: {
1913 if (aPrevState != theState) {
1914 /// call all sketch features redisplay, the expression state will be corrected in customize
1915 /// of distance presentation
1916 Events_ID anEventId = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1917 PartSet_Tools::sendSubFeaturesEvent(myCurrentSketch, anEventId);
1924 void PartSet_SketcherMgr::updateSelectionPriority(ObjectPtr theObject,
1925 FeaturePtr theFeature)
1927 if (!theObject.get() || !theFeature.get())
1930 AISObjectPtr anAIS = workshop()->displayer()->getAISObject(theObject);
1931 Handle(AIS_InteractiveObject) anAISIO;
1932 if (anAIS.get() != NULL) {
1933 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1936 if (!anAISIO.IsNull()) { // the presentation for the object is visualized
1937 int anAdditionalPriority = 0;
1939 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
1940 std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
1941 if (aSPFeature.get() != NULL) {
1943 // 2. Simple segments
1944 // 3. External objects (violet color)
1945 // 4. Auxiliary segments (dotted)
1946 // StdSelect_BRepSelectionTool::Load uses priority calculating:
1947 // Standard_Integer aPriority =
1948 // (thePriority == -1) ? GetStandardPriority (theShape, theType) : thePriority;
1949 // Priority of Vertex is 8, edge(segment) is 7.
1950 // It might be not corrected as provides the condition above.
1951 bool isExternal = aSPFeature->isExternal();
1952 bool isAuxiliary = PartSet_Tools::isAuxiliarySketchEntity(aSPFeature);
1954 if (!isExternal && !isAuxiliary)
1955 anAdditionalPriority = 30;
1958 anAdditionalPriority = 20;
1959 // auxiliary feature
1961 anAdditionalPriority = 10; /// auxiliary objects should have less priority that
1962 // edges/vertices of local selection on not-sketch objects
1964 Handle(ModuleBase_ResultPrs) aResult = Handle(ModuleBase_ResultPrs)::DownCast(anAISIO);
1965 if (!aResult.IsNull()) {
1966 aResult->setAdditionalSelectionPriority(anAdditionalPriority);
1972 XGUI_Workshop* PartSet_SketcherMgr::workshop() const
1974 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1975 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1976 return aConnector->workshop();
1979 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1981 return workshop()->operationMgr();