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_SketcherMgr.h"
22 #include "PartSet_Filters.h"
23 #include "PartSet_SketcherReentrantMgr.h"
24 #include "PartSet_Module.h"
25 #include "PartSet_MouseProcessor.h"
26 #include "PartSet_Tools.h"
27 #include "PartSet_WidgetSketchLabel.h"
28 #include "PartSet_WidgetEditor.h"
29 #include "PartSet_ResultSketchPrs.h"
30 #include "PartSet_ExternalPointsMgr.h"
31 #include "PartSet_PreviewSketchPlane.h"
33 #include <XGUI_ModuleConnector.h>
34 #include <XGUI_Displayer.h>
35 #include <XGUI_Workshop.h>
36 #include <XGUI_ContextMenuMgr.h>
37 #include <XGUI_Selection.h>
38 #include <XGUI_SelectionActivate.h>
39 #include <XGUI_SelectionMgr.h>
40 #include <XGUI_ModuleConnector.h>
41 #include <XGUI_PropertyPanel.h>
42 #include <XGUI_ViewerProxy.h>
43 #include <XGUI_OperationMgr.h>
44 #include <XGUI_ErrorMgr.h>
45 #include <XGUI_Tools.h>
47 #include <ModuleBase_IPropertyPanel.h>
48 #include <ModuleBase_ISelection.h>
49 #include <ModuleBase_IViewer.h>
50 #include <ModuleBase_IWorkshop.h>
51 #include <ModuleBase_IViewWindow.h>
52 #include <ModuleBase_ModelWidget.h>
53 #include <ModuleBase_Operation.h>
54 #include <ModuleBase_OperationFeature.h>
55 #include <ModuleBase_Operation.h>
56 #include <ModuleBase_WidgetEditor.h>
57 #include <ModuleBase_ViewerPrs.h>
58 #include <ModuleBase_Tools.h>
59 #include <ModuleBase_ResultPrs.h>
60 #include <ModuleBase_ViewerFilters.h>
62 #include <GeomDataAPI_Point2D.h>
64 #include <Events_Loop.h>
66 #include <SketchPlugin_Line.h>
67 #include <SketchPlugin_Sketch.h>
68 #include <SketchPlugin_Point.h>
69 #include <SketchPlugin_Arc.h>
70 #include <SketchPlugin_Circle.h>
71 #include <SketchPlugin_ConstraintLength.h>
72 #include <SketchPlugin_ConstraintDistance.h>
73 #include <SketchPlugin_ConstraintParallel.h>
74 #include <SketchPlugin_ConstraintPerpendicular.h>
75 #include <SketchPlugin_ConstraintRadius.h>
76 #include <SketchPlugin_ConstraintRigid.h>
77 #include <SketchPlugin_ConstraintHorizontal.h>
78 #include <SketchPlugin_ConstraintVertical.h>
79 #include <SketchPlugin_ConstraintEqual.h>
80 #include <SketchPlugin_ConstraintTangent.h>
81 #include <SketchPlugin_ConstraintCoincidence.h>
82 #include <SketchPlugin_Fillet.h>
83 #include <SketchPlugin_ConstraintMirror.h>
84 #include <SketchPlugin_ConstraintAngle.h>
85 #include <SketchPlugin_ConstraintCollinear.h>
86 #include <SketchPlugin_ConstraintMiddle.h>
87 #include <SketchPlugin_MultiRotation.h>
88 #include <SketchPlugin_MultiTranslation.h>
89 #include <SketchPlugin_IntersectionPoint.h>
90 #include <SketchPlugin_Projection.h>
91 #include <SketchPlugin_ConstraintDistanceAlongDir.h>
92 #include <SketchPlugin_ConstraintDistanceHorizontal.h>
93 #include <SketchPlugin_ConstraintDistanceVertical.h>
95 #include <SketcherPrs_Tools.h>
97 #include <SelectMgr_IndexedMapOfOwner.hxx>
98 #include <StdSelect_BRepOwner.hxx>
100 //#include <AIS_DimensionSelectionMode.hxx>
101 #include <AIS_Shape.hxx>
102 #include <AIS_Dimension.hxx>
104 #include <ModelAPI_Events.h>
105 #include <ModelAPI_Session.h>
106 #include <ModelAPI_AttributeString.h>
108 #include <ModelAPI_Validator.h>
109 #include <ModelAPI_Tools.h>
111 #include <QMouseEvent>
112 #include <QApplication>
114 #include <QMessageBox>
115 #include <QMainWindow>
117 //#define DEBUG_DO_NOT_BY_ENTER
118 //#define DEBUG_SKETCHER_ENTITIES
119 //#define DEBUG_SKETCH_ENTITIES_ON_MOVE
121 //#define DEBUG_CURSOR
123 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
124 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge,
125 /// put the function result as is to the list of results.
126 /// \param theOwner a viewer selected owner
127 /// \param theFeature a feature, where the attribute is searched
128 /// \param theSketch a current sketch
129 /// \param theSelectedAttribute an output list of attributes
130 /// \param theSelectedResults an output list of edge results
131 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
132 const FeaturePtr& theFeature, const FeaturePtr& theSketch,
133 const ResultPtr& theResult,
134 std::set<AttributePtr>& theSelectedAttributes,
135 std::set<ResultPtr>& theSelectedResults,
136 TopTools_MapOfShape& theShapes)
138 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
139 if (aBRepOwner.IsNull())
141 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
142 aBRepOwner->Selectable());
143 if (aBRepOwner->HasShape()) {
144 const TopoDS_Shape& aShape = aBRepOwner->Shape();
145 theShapes.Add(aShape);
146 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
147 if (aShapeType == TopAbs_VERTEX) {
148 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
150 if (aPntAttr.get() != NULL)
151 theSelectedAttributes.insert(aPntAttr);
153 else if (aShapeType == TopAbs_EDGE &&
154 theSelectedResults.find(theResult) == theSelectedResults.end()) {
155 theSelectedResults.insert(theResult);
160 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
161 : QObject(theModule), myModule(theModule), myIsEditLaunching(false), myIsDragging(false),
162 myDragDone(false), myIsMouseOverWindow(false),
163 myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
164 myIsPopupMenuActive(false), myExternalPointsMgr(0)
166 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
167 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
169 myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
171 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
172 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
174 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
175 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
177 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
178 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
180 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
181 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
183 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
184 XGUI_Workshop* aWorkshop = aConnector->workshop();
185 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
187 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
188 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
189 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
191 mySketchPlane = new PartSet_PreviewSketchPlane();
193 registerSelectionFilter(SF_SketchCirclePointFilter, new PartSet_CirclePointFilter(anIWorkshop));
194 registerSelectionFilter(SF_SketchPlaneFilter, new ModuleBase_ShapeInPlaneFilter());
197 PartSet_SketcherMgr::~PartSet_SketcherMgr()
199 delete mySketchPlane;
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 std::string anId = aWgt->attributeID();
652 if (anId == SketchPlugin_Constraint::VALUE() ||
653 anId == SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID() ||
654 anId == SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()) {
655 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
657 anEditor->showPopupEditor();
665 void PartSet_SketcherMgr::onApplicationStarted()
667 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
668 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
669 XGUI_Workshop* aWorkshop = aConnector->workshop();
670 PartSet_SketcherReentrantMgr* aReentranceMgr = myModule->sketchReentranceMgr();
672 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
673 if (aPropertyPanel) {
674 //connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
675 // this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
677 connect(aPropertyPanel, SIGNAL(noMoreWidgets(const std::string&)),
678 aReentranceMgr, SLOT(onNoMoreWidgets(const std::string&)));
679 //connect(aPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
680 // aReentranceMgr, SLOT(onWidgetActivated()));
683 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
684 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
685 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
687 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
688 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
689 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
692 //void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
694 //if (!myClickedPoint.myIsInitialized)
697 //ModuleBase_Operation* aOperation = getCurrentOperation();
698 // the distance constraint feature should not use the clickedd point
699 // this is workaround in order to don't throw down the flyout point value,
700 // set by execute() method of these type of features
701 //if (isDistanceOperation(aOperation))
704 //PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
706 // aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
710 void PartSet_SketcherMgr::onBeforeContextMenu()
712 myIsPopupMenuActive = true;
715 void PartSet_SketcherMgr::onAfterContextMenu()
717 myIsPopupMenuActive = false;
720 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
723 Handle(V3d_View) aView = theWnd->v3dView();
724 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
726 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
727 thePoint.setValue(aX, anY);
730 void PartSet_SketcherMgr::launchEditing()
732 if (!myCurrentSelection.empty()) {
733 FeaturePtr aFeature = myCurrentSelection.begin().key();
734 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
735 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
737 if (!aSPFeature->isExternal())
738 myModule->editFeature(aSPFeature);
740 // need to edit a feature (Projection/IntersectionPoint),
741 // which produces current External feature
742 FeaturePtr aProducerFeature = PartSet_Tools::findRefsToMeFeature(aFeature,
743 SketchPlugin_Projection::ID());
744 if (!aProducerFeature.get())
745 aProducerFeature = PartSet_Tools::findRefsToMeFeature(aFeature,
746 SketchPlugin_IntersectionPoint::ID());
747 if (aProducerFeature.get())
748 myModule->editFeature(aProducerFeature);
754 bool PartSet_SketcherMgr::sketchSolverError()
756 bool anError = false;
757 CompositeFeaturePtr aSketch = activeSketch();
759 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
760 anError = !aAttributeString->value().empty();
765 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
768 if (!theFeature.get() || !theFeature->data()->isValid())
771 CompositeFeaturePtr aSketch = activeSketch();
772 if (aSketch.get() && aSketch == theFeature) {
773 std::string aSolverError = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR())->value();
774 anError = ModuleBase_Tools::translate(aSketch->getKind(), aSolverError);
779 void PartSet_SketcherMgr::clearClickedFlags()
781 //myClickedPoint.clear();
782 myCurrentPoint.clear();
785 const QStringList& PartSet_SketcherMgr::replicationsIdList()
787 static QStringList aReplicationIds;
788 if (aReplicationIds.size() == 0) {
789 aReplicationIds << SketchPlugin_ConstraintMirror::ID().c_str();
790 aReplicationIds << SketchPlugin_MultiRotation::ID().c_str();
791 aReplicationIds << SketchPlugin_MultiTranslation::ID().c_str();
793 return aReplicationIds;
796 const QStringList& PartSet_SketcherMgr::constraintsIdList()
798 static QStringList aConstraintIds;
799 if (aConstraintIds.size() == 0) {
800 aConstraintIds << SketchPlugin_ConstraintLength::ID().c_str();
801 aConstraintIds << SketchPlugin_ConstraintDistance::ID().c_str();
802 aConstraintIds << SketchPlugin_ConstraintRigid::ID().c_str();
803 aConstraintIds << SketchPlugin_ConstraintRadius::ID().c_str();
804 aConstraintIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
805 aConstraintIds << SketchPlugin_ConstraintParallel::ID().c_str();
806 aConstraintIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
807 aConstraintIds << SketchPlugin_ConstraintVertical::ID().c_str();
808 aConstraintIds << SketchPlugin_ConstraintEqual::ID().c_str();
809 aConstraintIds << SketchPlugin_ConstraintTangent::ID().c_str();
810 aConstraintIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
811 aConstraintIds << SketchPlugin_ConstraintAngle::ID().c_str();
812 aConstraintIds << SketchPlugin_ConstraintCollinear::ID().c_str();
813 aConstraintIds << SketchPlugin_ConstraintMiddle::ID().c_str();
814 aConstraintIds << SketchPlugin_ConstraintMirror::ID().c_str();
815 aConstraintIds << SketchPlugin_MultiTranslation::ID().c_str();
816 aConstraintIds << SketchPlugin_MultiRotation::ID().c_str();
817 aConstraintIds << SketchPlugin_ConstraintDistanceAlongDir::ID().c_str();
818 aConstraintIds << SketchPlugin_ConstraintDistanceHorizontal::ID().c_str();
819 aConstraintIds << SketchPlugin_ConstraintDistanceVertical::ID().c_str();
821 return aConstraintIds;
824 void PartSet_SketcherMgr::sketchSelectionModes(const CompositeFeaturePtr& theSketch,
827 if (!theSketch.get() || !PartSet_Tools::sketchPlane(theSketch).get())
830 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
831 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
832 theModes.append(SketcherPrs_Tools::Sel_Constraint);
833 theModes.append(TopAbs_VERTEX);
834 theModes.append(TopAbs_EDGE);
837 Handle(AIS_InteractiveObject) PartSet_SketcherMgr::createPresentation(const ResultPtr& theResult)
839 Handle(AIS_InteractiveObject) aPrs;
841 FeaturePtr aFeature = ModelAPI_Feature::feature(theResult);
842 if (aFeature.get() && aFeature->getKind() == SketchPlugin_Sketch::ID()) {
843 aPrs = new PartSet_ResultSketchPrs(theResult);
848 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
850 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
853 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation) const
855 bool aNestedSketch = false;
857 FeaturePtr anActiveSketch = activeSketch();
858 if (anActiveSketch.get() && theOperation) {
859 ModuleBase_Operation* aSketchOperation = operationMgr()->findOperation(
860 anActiveSketch->getKind().c_str());
861 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
863 if (aSketchOperation && aFOperation) {
864 FeaturePtr aFeature = aFOperation->feature();
865 if (aFeature.get()) {
866 QStringList aGrantedOpIds = aSketchOperation->grantedOperationIds();
867 aNestedSketch = aGrantedOpIds.contains(aFeature->getKind().c_str());
871 return aNestedSketch;
874 bool PartSet_SketcherMgr::isNestedSketchFeature(const QString& theFeatureKind) const
876 bool aNestedSketch = false;
878 FeaturePtr anActiveSketch = activeSketch();
879 if (anActiveSketch.get()) {
880 ModuleBase_Operation* aSketchOperation = operationMgr()->findOperation(
881 anActiveSketch->getKind().c_str());
882 if (aSketchOperation) {
883 QStringList aGrantedOpIds = aSketchOperation->grantedOperationIds();
884 aNestedSketch = aGrantedOpIds.contains(theFeatureKind);
887 return aNestedSketch;
890 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation,
891 const CompositeFeaturePtr& theSketch) const
893 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
895 return aFOperation && !aFOperation->isEditOperation() &&
896 isNestedSketchOperation(aFOperation);
899 bool PartSet_SketcherMgr::isNestedEditOperation(ModuleBase_Operation* theOperation,
900 const CompositeFeaturePtr& theSketch) const
902 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
904 return aFOperation && aFOperation->isEditOperation() &&
905 isNestedSketchOperation(aFOperation);
908 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
910 return (theId == SketchPlugin_Line::ID()) ||
911 (theId == SketchPlugin_Point::ID()) ||
912 (theId == SketchPlugin_Arc::ID()) ||
913 (theId == SketchPlugin_Circle::ID());
916 bool PartSet_SketcherMgr::isExternalFeature(const FeaturePtr& theFeature)
918 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
919 std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
920 return aSPFeature.get() && aSPFeature->isExternal();
923 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
925 std::string anId = theOperation ? theOperation->id().toStdString() : "";
927 return isDistanceKind(anId);
930 bool PartSet_SketcherMgr::isDistanceKind(std::string& theKind)
932 return (theKind == SketchPlugin_ConstraintLength::ID()) ||
933 (theKind == SketchPlugin_ConstraintDistance::ID()) ||
934 (theKind == SketchPlugin_ConstraintRadius::ID()) ||
935 (theKind == SketchPlugin_ConstraintAngle::ID()) ||
936 (theKind == SketchPlugin_ConstraintDistanceHorizontal::ID()) ||
937 (theKind == SketchPlugin_ConstraintDistanceVertical::ID()) ||
938 (theKind == SketchPlugin_ConstraintDistanceAlongDir::ID());
941 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
943 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
944 (getCurrentOperation());
948 myModule->onViewTransformed();
950 // Display all sketcher sub-Objects
951 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
952 double aSizeOfView = 0;
953 std::shared_ptr<GeomAPI_Pnt> aCentralPoint;
954 if (aFOperation->isEditOperation() &&
955 mySketchPlane->getDefaultSizeOfView(myCurrentSketch, aSizeOfView, aCentralPoint)) {
956 mySketchPlane->setSizeOfView(aSizeOfView, true, aCentralPoint);
959 mySketchPlane->createSketchPlane(myCurrentSketch, myModule->workshop());
960 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
962 // Hide sketcher result
963 std::list<ResultPtr> aResults = myCurrentSketch->results();
964 std::list<ResultPtr>::const_iterator aIt;
965 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
966 (*aIt)->setDisplayed(false);
968 myCurrentSketch->setDisplayed(false);
970 // Remove invalid sketch entities
971 std::set<FeaturePtr> anInvalidFeatures;
972 ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
973 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
974 for (int i = 0; i < aNumberOfSubs; i++) {
975 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
976 if (aFeature.get()) {
977 if (!aFactory->validate(aFeature))
978 anInvalidFeatures.insert(aFeature);
981 if (!anInvalidFeatures.empty()) {
982 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
983 ModelAPI_Tools::findAllReferences(anInvalidFeatures, aReferences, false);
985 std::set<FeaturePtr>::const_iterator anIt = anInvalidFeatures.begin(),
986 aLast = anInvalidFeatures.end();
987 // separate features to references to parameter features and references to others
988 QStringList anInvalidFeatureNames;
989 for (; anIt != aLast; anIt++) {
990 FeaturePtr aFeature = *anIt;
992 anInvalidFeatureNames.append(aFeature->name().c_str());
994 std::string aPrefixInfo = QString("Invalid features of the sketch will be deleted: %1.\n\n").
995 arg(anInvalidFeatureNames.join(", ")).toStdString().c_str();
996 std::set<FeaturePtr> aFeatureRefsToDelete;
997 if (ModuleBase_Tools::askToDelete(anInvalidFeatures, aReferences, aConnector->desktop(),
998 aFeatureRefsToDelete, aPrefixInfo)) {
999 if (!aFeatureRefsToDelete.empty())
1000 anInvalidFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1001 ModelAPI_Tools::removeFeatures(anInvalidFeatures, true);
1002 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
1003 // TODO: call the next method in the XGUI_OperationMgr::onOperationStarted().
1004 workshop()->errorMgr()->updateAcceptAllAction(myCurrentSketch);
1008 // update state of overconstraint listener should be done before sketch features/results
1009 // display (as the display will ask custom color from the listener)
1010 myModule->overconstraintListener()->setActive(true);
1011 // Display sketcher objects
1013 Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1014 const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
1015 aNumberOfSubs = myCurrentSketch->numberOfSubs();
1016 for (int i = 0; i < aNumberOfSubs; i++) {
1017 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1018 #ifdef DEBUG_SKETCHER_ENTITIES
1019 anInfo.append(ModuleBase_Tools::objectInfo(aFeature));
1021 std::list<ResultPtr> aResults = aFeature->results();
1022 std::list<ResultPtr>::const_iterator aIt;
1023 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1024 if ((*aIt)->isDisplayed())
1025 // Display object if it was created outside of GUI
1026 aECreator->sendUpdated((*aIt), EVENT_DISP);
1028 (*aIt)->setDisplayed(true);
1030 if (aFeature->isDisplayed())
1031 aECreator->sendUpdated(aFeature, EVENT_DISP);
1033 aFeature->setDisplayed(true);
1035 #ifdef DEBUG_SKETCHER_ENTITIES
1036 QString anInfoStr = anInfo.join(";\t");
1037 qDebug(QString("startSketch: %1, %2").arg(anInfo.size()).arg(anInfoStr).toStdString().c_str());
1040 bool aHasPlane = false;
1041 std::shared_ptr<GeomAPI_Pln> aPln;
1042 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
1043 Handle(SelectMgr_Filter) aFilter = myModule->selectionFilter(SF_SketchPlaneFilter);
1044 if (!aFilter.IsNull())
1045 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(aPln);
1047 workshop()->selectionActivate()->updateSelectionFilters();
1048 workshop()->selectionActivate()->updateSelectionModes();
1050 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1052 myExternalPointsMgr = new PartSet_ExternalPointsMgr(myModule->workshop(), myCurrentSketch);
1055 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
1057 myIsMouseOverWindow = false;
1058 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
1059 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
1060 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
1062 if (myExternalPointsMgr) {
1063 delete myExternalPointsMgr;
1064 myExternalPointsMgr = 0;
1067 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
1069 DataPtr aData = myCurrentSketch->data();
1070 if (!aData->isValid()) {
1071 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1072 // The sketch was aborted
1073 myCurrentSketch = CompositeFeaturePtr();
1074 mySketchPlane->eraseSketchPlane(myModule->workshop());
1076 // Erase all sketcher objects
1077 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1078 foreach (ObjectPtr aObj, aObjects) {
1079 DataPtr aObjData = aObj->data();
1080 if (!aObjData->isValid())
1081 aObj->setDisplayed(false);
1085 // Hide all sketcher sub-Objects
1086 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
1087 for (int i = 0; i < aNumberOfSubs; i++) {
1088 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1089 std::list<ResultPtr> aResults = aFeature->results();
1090 std::list<ResultPtr>::const_iterator aIt;
1091 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1092 (*aIt)->setDisplayed(false);
1094 aFeature->setDisplayed(false);
1096 // Display sketcher result
1097 std::list<ResultPtr> aResults = myCurrentSketch->results();
1098 std::list<ResultPtr>::const_iterator aIt;
1099 Events_Loop* aLoop = Events_Loop::loop();
1100 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1102 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1104 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1105 if (!aFOperation->isDisplayedOnStart(*aIt)) {
1106 (*aIt)->setDisplayed(true);
1107 // this display event is needed because sketch already may have "displayed" state,
1108 // but not displayed while it is still active (issue 613, abort of existing sketch)
1109 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
1112 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
1113 myCurrentSketch->setDisplayed(true);
1115 myCurrentSketch = CompositeFeaturePtr();
1116 mySketchPlane->eraseSketchPlane(myModule->workshop());
1118 Events_Loop::loop()->flush(aDispEvent);
1120 workshop()->selectionActivate()->updateSelectionFilters();
1121 workshop()->selectionActivate()->updateSelectionModes();
1124 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
1126 if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
1127 QCursor* aCurrentCursor = QApplication::overrideCursor();
1128 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
1129 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
1131 qDebug("startNestedSketch() : Qt::CrossCursor");
1137 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
1139 myIsMouseOverViewProcessed = true;
1140 operationMgr()->onValidateOperation();
1141 // when sketch nested operation is stopped the cursor should be restored unconditionally
1142 //if (canChangeCursor(theOperation)) {
1143 QApplication::restoreOverrideCursor();
1145 qDebug("stopNestedSketch() : None");
1148 /// improvement to deselect automatically all eventual selected objects, when
1149 // returning to the neutral point of the Sketcher
1150 bool isClearSelectionPossible = true;
1151 if (myIsEditLaunching) {
1152 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1155 FeaturePtr aFeature = aFOperation->feature();
1156 if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
1157 isClearSelectionPossible = false;
1161 if (isClearSelectionPossible)
1162 workshop()->selector()->clearSelection();
1165 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
1167 if (isNestedCreateOperation(theOperation, activeSketch())) {
1168 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1171 FeaturePtr aFeature = aFOperation->feature();
1172 // it is necessary to check the the feature data validity because
1173 // some kind of features are removed by an operation commit(the macro state of a feature)
1174 if (aFeature.get() && aFeature->data()->isValid()) {
1175 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
1181 bool PartSet_SketcherMgr::sketchSelectionFilter(const XGUI_SelectionFilterType theFilterType)
1183 return mySelectionFilterTypes.find(theFilterType) != mySelectionFilterTypes.end();
1186 void PartSet_SketcherMgr::registerSelectionFilter(const XGUI_SelectionFilterType theFilterType,
1187 const Handle(SelectMgr_Filter)& theFilter)
1189 mySelectionFilterTypes.insert(theFilterType);
1190 myModule->registerSelectionFilter(theFilterType, theFilter);
1193 bool PartSet_SketcherMgr::operationActivatedByPreselection()
1195 bool isOperationStopped = false;
1196 ModuleBase_Operation* anOperation = getCurrentOperation();
1197 if(anOperation && isNestedSketchOperation(anOperation)) {
1198 // Set final definitions if they are necessary
1199 //propertyPanelDefined(aOperation);
1200 /// Commit sketcher operations automatically
1201 /// distance operation are able to show popup editor to modify the distance value
1202 /// after entering the value, the operation should be committed/aborted(by Esc key)
1203 bool aCanCommitOperation = true;
1204 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1206 if (aFOperation && PartSet_SketcherMgr::isDistanceOperation(aFOperation)) {
1207 bool aValueAccepted = setDistanceValueByPreselection(anOperation, myModule->workshop(),
1208 aCanCommitOperation);
1209 if (!aValueAccepted)
1210 return isOperationStopped;
1213 if (aCanCommitOperation)
1214 isOperationStopped = anOperation->commit();
1216 anOperation->abort();
1217 isOperationStopped = true;
1220 return isOperationStopped;
1223 bool PartSet_SketcherMgr::canUndo() const
1225 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1228 bool PartSet_SketcherMgr::canRedo() const
1230 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1233 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1235 bool aCanErase = true;
1236 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1237 if (myCurrentSketch.get()) {
1238 return !isObjectOfSketch(theObject);
1243 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1245 bool aCanDisplay = true;
1247 bool aHasActiveSketch = activeSketch().get() != NULL;
1248 if (aHasActiveSketch) {
1249 // 1. the sketch feature should not be displayed during the sketch active operation
1250 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1251 // nested features can be visualized
1252 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1253 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1254 aCanDisplay = false;
1256 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1257 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1258 /// some sketch entities should be never shown, e.g. projection feature
1259 if (aSketchFeature.get())
1260 aCanDisplay = aSketchFeature->canBeDisplayed();
1262 else { // there are no an active sketch
1263 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1264 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1265 if (aFeature.get() != NULL) {
1266 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1267 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1268 if (aSketchFeature.get()) {
1269 aCanDisplay = false;
1274 // 3. the method should not filter the objects, which are not related to the current operation.
1275 // The object is filtered just if it is a current operation feature or this feature result
1277 bool isObjectFound = false;
1278 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1279 (getCurrentOperation());
1281 FeaturePtr aFeature = aFOperation->feature();
1282 if (aFeature.get()) {
1283 std::list<ResultPtr> aResults = aFeature->results();
1284 if (theObject == aFeature)
1285 isObjectFound = true;
1287 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1288 for (; anIt != aLast && !isObjectFound; anIt++) {
1289 isObjectFound = *anIt == theObject;
1294 if (isObjectFound) {
1295 // 4. For created nested feature operation do not display the created feature if
1296 // the mouse curstor leaves the OCC window.
1297 // The correction cases, which ignores this condition:
1298 // a. the property panel values modification
1299 // b. the popup menu activated
1300 // c. widget editor control
1301 #ifndef DEBUG_DO_NOT_BY_ENTER
1302 if (isNestedCreateOperation(getCurrentOperation(), activeSketch())) {
1303 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1304 ModuleBase_WidgetEditor* anEditorWdg =
1305 anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1306 // the active widget editor should not influence here. The presentation should be visible
1307 // always when this widget is active.
1308 if (!anEditorWdg && !myIsPopupMenuActive) {
1309 // during a nested create operation, the feature is redisplayed only
1310 // if the mouse over view
1311 // of there was a value modified in the property panel after the mouse left the view
1312 aCanDisplay = canDisplayCurrentCreatedFeature();
1319 // checks the sketcher constraints visibility according to active sketch check box states
1321 bool aProcessed = false;
1322 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1323 if (aFeature.get()) {
1324 bool aConstraintDisplayed = canDisplayConstraint(aFeature, PartSet_Tools::Any, aProcessed);
1326 aCanDisplay = aConstraintDisplayed;
1333 bool PartSet_SketcherMgr::canDisplayConstraint(const FeaturePtr& theFeature,
1334 const PartSet_Tools::ConstraintVisibleState& theState,
1335 bool& isProcessed) const
1337 bool aSwitchedOn = true;
1339 const QStringList& aConstrIds = constraintsIdList();
1341 std::string aKind = theFeature->getKind();
1342 if (aConstrIds.contains(QString(aKind.c_str()))) {
1343 bool isTypedConstraint = false;
1346 case PartSet_Tools::Dimensional: {
1347 bool isDistance = isDistanceKind(aKind);
1350 aSwitchedOn = myIsConstraintsShown[theState];
1354 case PartSet_Tools::Geometrical: {
1355 bool isGeometrical = !isDistanceKind(aKind);
1356 if (isGeometrical) {
1358 aSwitchedOn = myIsConstraintsShown[theState];
1362 case PartSet_Tools::Any: {
1364 bool isDistance = isDistanceKind(aKind);
1366 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Dimensional];
1368 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Geometrical];
1378 /*void PartSet_SketcherMgr::processHiddenObject(const std::list<ObjectPtr>& theObjects)
1380 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1381 (getCurrentOperation());
1382 if (aFOperation && myCurrentSketch.get()) {
1383 // find results of the current operation
1384 // these results should not be proposed to be deleted
1385 FeaturePtr anOperationFeature = aFOperation->feature();
1386 std::list<ResultPtr> anOperationResultList = anOperationFeature->results();
1387 std::set<ResultPtr> anOperationResults;
1388 std::list<ResultPtr>::const_iterator aRIt = anOperationResultList.begin(),
1389 aRLast = anOperationResultList.end();
1390 for (; aRIt != aRLast; aRIt++)
1391 anOperationResults.insert(*aRIt);
1393 std::set<FeaturePtr> anObjectsToBeDeleted;
1394 QStringList anObjectsToBeDeletedNames;
1395 std::list<ObjectPtr>::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1396 for (; anIt != aLast; anIt++) {
1397 ObjectPtr anObject = *anIt;
1398 bool aCanErase = true;
1399 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1400 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1401 // the result is found between current feature results
1402 if (anOperationResults.find(aResult) != anOperationResults.end())
1405 if (aResult.get()) {
1406 // Display sketcher objects
1407 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1408 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1409 std::list<ResultPtr> aResults = aFeature->results();
1410 std::list<ResultPtr>::const_iterator anIt;
1411 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1412 aCanErase = *anIt != aResult;
1417 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1418 if (aFeature.get() && anObjectsToBeDeleted.find(aFeature) == anObjectsToBeDeleted.end()) {
1419 anObjectsToBeDeleted.insert(aFeature);
1420 anObjectsToBeDeletedNames.append(aFeature->name().c_str());
1424 if (!anObjectsToBeDeleted.empty()) {
1425 QString aFeatureNames = anObjectsToBeDeletedNames.join(", ");
1426 QString aMessage = tr("The following features have incorrect presentation and \
1427 will be hidden: %1. Would you like to delete them?")
1428 .arg(aFeatureNames);
1429 int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Features hide"),
1430 aMessage, QMessageBox::Ok | QMessageBox::Cancel,
1431 QMessageBox::Cancel);
1432 if (anAnswer == QMessageBox::Ok) {
1433 QObjectPtrList anObjects;
1434 std::set<FeaturePtr>::const_iterator anIt = anObjectsToBeDeleted.begin(),
1435 aLast = anObjectsToBeDeleted.end();
1436 for (; anIt != aLast; anIt++)
1437 anObjects.append(*anIt);
1438 SessionPtr aMgr = ModelAPI_Session::get();
1439 DocumentPtr aDoc = aMgr->activeDocument();
1440 bool aIsOp = aMgr->isOperation();
1442 aMgr->startOperation();
1443 workshop()->deleteFeatures(anObjects);
1444 //static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
1445 //static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
1446 //Events_Loop::loop()->flush(aDeletedEvent);
1447 //Events_Loop::loop()->flush(aRedispEvent);
1450 aMgr->finishOperation();
1456 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1458 bool aCanDisplay = myIsMouseOverWindow;
1460 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1462 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1467 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1469 return isNestedCreateOperation(theOperation, activeSketch()) ||
1470 myModule->sketchReentranceMgr()->isInternalEditActive();
1473 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
1475 return myIsConstraintsShown;
1478 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1480 bool isFoundObject = false;
1482 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1483 if (anObjectFeature.get()) {
1484 int aSize = myCurrentSketch->numberOfSubs();
1485 for (int i = 0; i < aSize && !isFoundObject; i++) {
1486 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1487 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1490 return isFoundObject;
1493 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePlane)
1495 Handle(SelectMgr_Filter) aFilter = myModule->selectionFilter(SF_SketchPlaneFilter);
1496 if (!aFilter.IsNull())
1497 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(thePlane);
1499 workshop()->selectionActivate()->updateSelectionModes();
1502 bool PartSet_SketcherMgr::setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
1503 ModuleBase_IWorkshop* theWorkshop,
1504 bool& theCanCommitOperation)
1506 bool isValueAccepted = false;
1507 theCanCommitOperation = false;
1509 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1511 FeaturePtr aFeature = aFOperation->feature();
1512 // editor is shown only if all attribute references are filled by preseletion
1513 bool anAllRefAttrInitialized = true;
1515 std::list<AttributePtr> aRefAttrs = aFeature->data()->attributes(
1516 ModelAPI_AttributeRefAttr::typeId());
1517 std::list<AttributePtr>::const_iterator anIt = aRefAttrs.begin(), aLast = aRefAttrs.end();
1518 for (; anIt != aLast && anAllRefAttrInitialized; anIt++) {
1519 anAllRefAttrInitialized = (*anIt)->isInitialized();
1521 if (anAllRefAttrInitialized) {
1522 // Activate dimension value editing on double click
1523 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
1524 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
1525 // Find corresponded widget to activate value editing
1526 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
1527 if (aWgt->attributeID() == "ConstraintValue") {
1528 // the featue should be displayed in order to find the AIS text position,
1529 // the place where the editor will be shown
1530 aFeature->setDisplayed(true);
1531 /// the execute is necessary to perform in the feature compute for flyout position
1532 aFeature->execute();
1534 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1535 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1537 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
1539 int aX = 0, anY = 0;
1541 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(theWorkshop);
1542 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1543 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
1544 Handle(AIS_InteractiveObject) anAISIO;
1545 if (anAIS.get() != NULL) {
1546 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1548 if (anAIS.get() != NULL) {
1549 Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1551 if (!anAISIO.IsNull()) {
1552 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
1553 if (!aDim.IsNull()) {
1554 gp_Pnt aPosition = aDim->GetTextPosition();
1556 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
1557 Handle(V3d_View) aView = aViewer->activeView();
1559 aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
1561 QWidget* aViewPort = aViewer->activeViewPort();
1562 QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
1567 anEditor->setCursorPosition(aX, anY);
1568 isValueAccepted = anEditor->showPopupEditor(false);
1569 theCanCommitOperation = true;
1575 return isValueAccepted;
1578 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1579 const FeaturePtr& theSketch,
1580 ModuleBase_IWorkshop* theWorkshop,
1581 const FeatureToSelectionMap& theSelection,
1582 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1584 if (theFeature.get() == NULL)
1587 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1588 SelectionInfo anInfo = anIt.value();
1589 std::set<AttributePtr> aSelectedAttributes = anInfo.myAttributes;
1590 std::set<ResultPtr> aSelectedResults = anInfo.myResults;
1592 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1594 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1595 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1597 // 1. found the feature's owners. Check the AIS objects of the constructions
1598 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1599 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1600 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1602 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1603 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1604 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1605 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1606 if (!anOwner.IsNull())
1607 theOwnersToSelect.Add(anOwner);
1611 // 2. found the feature results's owners
1612 std::list<ResultPtr> aResults = theFeature->results();
1613 std::list<ResultPtr>::const_iterator aIt;
1615 bool isSameShape = false;
1616 if (aResults.size() > 0) {
1617 ResultPtr aFirstResult = theFeature->firstResult();
1618 if (aFirstResult.get() && aFirstResult->shape().get()) {
1619 TopoDS_Shape aFirstShape = aFirstResult->shape()->impl<TopoDS_Shape>();
1620 isSameShape = aFirstShape.IsEqual(anInfo.myFirstResultShape);
1623 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1624 ResultPtr aResult = *aIt;
1625 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1626 if (aAISObj.get() == NULL)
1628 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1630 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1631 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1632 bool aFoundLocalShape = false;
1633 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1634 Handle(StdSelect_BRepOwner) anOwner =
1635 Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1636 if ( anOwner.IsNull() || !anOwner->HasShape() || theOwnersToSelect.FindIndex(anOwner))
1638 const TopoDS_Shape& aShape = anOwner->Shape();
1639 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1640 if (aShapeType == TopAbs_VERTEX) {
1641 AttributePtr aPntAttr =
1642 PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1643 if (aPntAttr.get() != NULL &&
1644 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end())
1645 theOwnersToSelect.Add(anOwner);
1646 else if (isSameShape && anInfo.myLocalSelectedShapes.Contains(aShape)) {
1647 theOwnersToSelect.Add(anOwner);
1650 else if (aShapeType == TopAbs_EDGE) {
1651 if (isSameShape && anInfo.myLocalSelectedShapes.Contains(aShape)) {
1652 // try to restore local selection on Shape result
1653 // we can do this only if the shape was not changed
1654 theOwnersToSelect.Add(anOwner);
1655 aFoundLocalShape = true;
1660 if (!aFoundLocalShape) {
1661 // result owners are put in the list of selection only if local selected shapes were not
1663 if (aSelectedResults.find(aResult) != aSelectedResults.end()) {
1664 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1665 Handle(StdSelect_BRepOwner) anOwner =
1666 Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1667 if ( anOwner.IsNull() || !anOwner->HasShape() || theOwnersToSelect.FindIndex(anOwner))
1669 // select whole result
1670 theOwnersToSelect.Add(anOwner);
1677 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
1678 const bool isToConnect)
1680 //Temporary commented as we do not modify values in property panel
1682 //connect(theWidget, SIGNAL(beforeValuesChanged()),
1683 // this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1684 //connect(theWidget, SIGNAL(afterValuesChanged()),
1685 // this, SLOT(onAfterValuesChangedInPropertyPanel()));
1686 connect(theWidget, SIGNAL(afterValuesChanged()),
1687 myModule->sketchReentranceMgr(), SLOT(onAfterValuesChangedInPropertyPanel()));
1690 //disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1691 // this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1692 //disconnect(theWidget, SIGNAL(afterValuesChanged()),
1693 // this, SLOT(onAfterValuesChangedInPropertyPanel()));
1694 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1695 myModule->sketchReentranceMgr(), SLOT(onAfterValuesChangedInPropertyPanel()));
1699 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1701 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1702 (getCurrentOperation());
1704 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1705 isNestedSketchOperation(aFOperation) &&
1706 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1707 FeaturePtr aFeature = aFOperation->feature();
1708 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1713 void PartSet_SketcherMgr::customizePresentation(const ObjectPtr& theObject)
1715 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1716 (getCurrentOperation());
1717 if (aFOperation && (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1718 isNestedSketchOperation(aFOperation)))
1719 SketcherPrs_Tools::sendExpressionShownEvent(myIsConstraintsShown[PartSet_Tools::Expressions]);
1721 // update entities selection priorities
1722 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1723 if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
1724 // update priority for feature
1725 updateSelectionPriority(aFeature, aFeature);
1726 // update priority for results of the feature
1727 std::list<ResultPtr> aResults = aFeature->results();
1728 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLastIt = aResults.end();
1729 for (; anIt != aLastIt; anIt++)
1730 updateSelectionPriority(*anIt, aFeature);
1734 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1736 return myModule->workshop()->currentOperation();
1739 //**************************************************************
1740 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1742 ModuleBase_ModelWidget* aWidget = 0;
1743 ModuleBase_Operation* anOperation = getCurrentOperation();
1745 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1747 aWidget = aPanel->activeWidget();
1752 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1753 const bool isEditOperation,
1754 const bool isToDisplay,
1755 const bool isFlushRedisplay)
1757 #ifdef DEBUG_DO_NOT_BY_ENTER
1761 if (isEditOperation || !theFeature.get())
1764 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1765 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1767 // 1. change visibility of the object itself, here the presentable object is processed,
1768 // e.g. constraints features
1769 //FeaturePtr aFeature = aFOperation->feature();
1770 std::list<ResultPtr> aResults = theFeature->results();
1772 theFeature->setDisplayed(true);
1774 theFeature->setDisplayed(false);
1776 // change visibility of the object results, e.g. non-constraint features
1777 std::list<ResultPtr>::const_iterator aIt;
1778 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1780 (*aIt)->setDisplayed(true);
1783 (*aIt)->setDisplayed(false);
1786 if (isFlushRedisplay)
1787 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1790 void PartSet_SketcherMgr::storeSelection(const SelectionType theType,
1791 PartSet_SketcherMgr::FeatureToSelectionMap& theCurrentSelection)
1793 if (!myCurrentSketch.get())
1796 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1797 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1798 QList<ModuleBase_ViewerPrsPtr> aStoredPrs;
1800 if (theType == ST_HighlightType || theType == ST_SelectAndHighlightType)
1801 aStoredPrs = aSelect->getHighlighted();
1803 QList<FeaturePtr> aFeatureList;
1804 if (theType == ST_SelectAndHighlightType || theType == ST_SelectType) {
1805 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected(
1806 ModuleBase_ISelection::AllControls);
1807 aStoredPrs.append(aSelected);
1810 // 1. it is necessary to save current selection in order to restore it after the features moving
1811 theCurrentSelection.clear();
1813 QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = aStoredPrs.begin(),
1814 aLast = aStoredPrs.end();
1816 CompositeFeaturePtr aSketch = activeSketch();
1817 for (; anIt != aLast; anIt++) {
1818 ModuleBase_ViewerPrsPtr aPrs = *anIt;
1819 ObjectPtr anObject = aPrs->object();
1820 if (!anObject.get())
1823 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1824 FeaturePtr aFeature;
1826 aFeature = ModelAPI_Feature::feature(aResult);
1828 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1830 if (!aFeature.get())
1833 std::set<AttributePtr> aSelectedAttributes;
1834 std::set<ResultPtr> aSelectedResults;
1835 SelectionInfo anInfo;
1836 if (theCurrentSelection.find(aFeature) != theCurrentSelection.end())
1837 anInfo = theCurrentSelection.find(aFeature).value();
1839 TopoDS_Shape aFirstShape;
1840 ResultPtr aFirstResult = aFeature->firstResult();
1841 if (aFirstResult.get() && aFirstResult->shape().get())
1842 aFirstShape = aFirstResult->shape()->impl<TopoDS_Shape>();
1843 anInfo.myFirstResultShape = aFirstShape;
1844 Handle(SelectMgr_EntityOwner) anOwner = aPrs->owner();
1845 if (aResult.get()) {
1846 getAttributesOrResults(anOwner, aFeature, aSketch, aResult,
1847 anInfo.myAttributes, anInfo.myResults, anInfo.myLocalSelectedShapes);
1850 std::list<ResultPtr> aResults = aFeature->results();
1851 std::list<ResultPtr>::const_iterator aIt;
1852 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1853 ResultPtr aResult = *aIt;
1854 getAttributesOrResults(anOwner, aFeature, aSketch, aResult,
1855 anInfo.myAttributes, anInfo.myResults, anInfo.myLocalSelectedShapes);
1858 theCurrentSelection[aFeature] = anInfo;
1860 //qDebug(QString(" storeSelection: %1").arg(theCurrentSelection.size()).toStdString().c_str());
1863 void PartSet_SketcherMgr::restoreSelection(
1864 PartSet_SketcherMgr::FeatureToSelectionMap& theCurrentSelection)
1866 if (!myCurrentSketch.get())
1869 //qDebug(QString("restoreSelection: %1").arg(theCurrentSelection.size()).toStdString().c_str());
1870 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1871 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1872 FeatureToSelectionMap::const_iterator aSIt = theCurrentSelection.begin(),
1873 aSLast = theCurrentSelection.end();
1874 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1875 anOwnersToSelect.Clear();
1876 for (; aSIt != aSLast; aSIt++) {
1877 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, theCurrentSelection,
1880 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1883 void PartSet_SketcherMgr::onShowConstraintsToggle(int theType, bool theState)
1885 PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
1887 updateBySketchParameters(aType, theState);
1890 void PartSet_SketcherMgr::updateBySketchParameters(
1891 const PartSet_Tools::ConstraintVisibleState& theType,
1894 if (myCurrentSketch.get() == NULL)
1897 bool aPrevState = myIsConstraintsShown[theType];
1898 myIsConstraintsShown[theType] = theState;
1901 case PartSet_Tools::Geometrical:
1902 case PartSet_Tools::Dimensional: {
1903 if (aPrevState != theState) {
1904 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1905 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1906 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
1907 for (int i = 0; i < aNumberOfSubs; i++) {
1908 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1909 bool aProcessed = false;
1910 bool aConstraintDisplayed = canDisplayConstraint(aSubFeature, theType, aProcessed);
1912 aSubFeature->setDisplayed(aConstraintDisplayed);
1914 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1918 case PartSet_Tools::Expressions: {
1919 if (aPrevState != theState) {
1920 /// call all sketch features redisplay, the expression state will be corrected in customize
1921 /// of distance presentation
1922 Events_ID anEventId = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1923 PartSet_Tools::sendSubFeaturesEvent(myCurrentSketch, anEventId);
1930 void PartSet_SketcherMgr::updateSelectionPriority(ObjectPtr theObject,
1931 FeaturePtr theFeature)
1933 if (!theObject.get() || !theFeature.get())
1936 AISObjectPtr anAIS = workshop()->displayer()->getAISObject(theObject);
1937 Handle(AIS_InteractiveObject) anAISIO;
1938 if (anAIS.get() != NULL) {
1939 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1942 if (!anAISIO.IsNull()) { // the presentation for the object is visualized
1943 int anAdditionalPriority = 0;
1945 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
1946 std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
1947 if (aSPFeature.get() != NULL) {
1949 // 2. Simple segments
1950 // 3. External objects (violet color)
1951 // 4. Auxiliary segments (dotted)
1952 // StdSelect_BRepSelectionTool::Load uses priority calculating:
1953 // Standard_Integer aPriority =
1954 // (thePriority == -1) ? GetStandardPriority (theShape, theType) : thePriority;
1955 // Priority of Vertex is 8, edge(segment) is 7.
1956 // It might be not corrected as provides the condition above.
1957 bool isExternal = aSPFeature->isExternal();
1958 bool isAuxiliary = PartSet_Tools::isAuxiliarySketchEntity(aSPFeature);
1960 if (!isExternal && !isAuxiliary)
1961 anAdditionalPriority = 30;
1964 anAdditionalPriority = 20;
1965 // auxiliary feature
1967 anAdditionalPriority = 10; /// auxiliary objects should have less priority that
1968 // edges/vertices of local selection on not-sketch objects
1970 Handle(ModuleBase_ResultPrs) aResult = Handle(ModuleBase_ResultPrs)::DownCast(anAISIO);
1971 if (!aResult.IsNull()) {
1972 aResult->setAdditionalSelectionPriority(anAdditionalPriority);
1978 XGUI_Workshop* PartSet_SketcherMgr::workshop() const
1980 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1981 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1982 return aConnector->workshop();
1985 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1987 return workshop()->operationMgr();