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 FeaturePtr aProjectionFeature = PartSet_Tools::findRefsToMeFeature(aFeature,
739 SketchPlugin_Projection::ID());
740 if (aProjectionFeature.get())
741 myModule->editFeature(aProjectionFeature);
747 bool PartSet_SketcherMgr::sketchSolverError()
749 bool anError = false;
750 CompositeFeaturePtr aSketch = activeSketch();
752 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
753 anError = !aAttributeString->value().empty();
758 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
761 if (!theFeature.get() || !theFeature->data()->isValid())
764 CompositeFeaturePtr aSketch = activeSketch();
765 if (aSketch.get() && aSketch == theFeature) {
766 std::string aSolverError = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR())->value();
767 anError = ModuleBase_Tools::translate(aSketch->getKind(), aSolverError);
772 void PartSet_SketcherMgr::clearClickedFlags()
774 //myClickedPoint.clear();
775 myCurrentPoint.clear();
778 const QStringList& PartSet_SketcherMgr::replicationsIdList()
780 static QStringList aReplicationIds;
781 if (aReplicationIds.size() == 0) {
782 aReplicationIds << SketchPlugin_ConstraintMirror::ID().c_str();
783 aReplicationIds << SketchPlugin_MultiRotation::ID().c_str();
784 aReplicationIds << SketchPlugin_MultiTranslation::ID().c_str();
786 return aReplicationIds;
789 const QStringList& PartSet_SketcherMgr::constraintsIdList()
791 static QStringList aConstraintIds;
792 if (aConstraintIds.size() == 0) {
793 aConstraintIds << SketchPlugin_ConstraintLength::ID().c_str();
794 aConstraintIds << SketchPlugin_ConstraintDistance::ID().c_str();
795 aConstraintIds << SketchPlugin_ConstraintRigid::ID().c_str();
796 aConstraintIds << SketchPlugin_ConstraintRadius::ID().c_str();
797 aConstraintIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
798 aConstraintIds << SketchPlugin_ConstraintParallel::ID().c_str();
799 aConstraintIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
800 aConstraintIds << SketchPlugin_ConstraintVertical::ID().c_str();
801 aConstraintIds << SketchPlugin_ConstraintEqual::ID().c_str();
802 aConstraintIds << SketchPlugin_ConstraintTangent::ID().c_str();
803 aConstraintIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
804 aConstraintIds << SketchPlugin_ConstraintAngle::ID().c_str();
805 aConstraintIds << SketchPlugin_ConstraintCollinear::ID().c_str();
806 aConstraintIds << SketchPlugin_ConstraintMiddle::ID().c_str();
807 aConstraintIds << SketchPlugin_ConstraintMirror::ID().c_str();
808 aConstraintIds << SketchPlugin_MultiTranslation::ID().c_str();
809 aConstraintIds << SketchPlugin_MultiRotation::ID().c_str();
810 aConstraintIds << SketchPlugin_ConstraintDistanceAlongDir::ID().c_str();
811 aConstraintIds << SketchPlugin_ConstraintDistanceHorizontal::ID().c_str();
812 aConstraintIds << SketchPlugin_ConstraintDistanceVertical::ID().c_str();
814 return aConstraintIds;
817 void PartSet_SketcherMgr::sketchSelectionModes(const CompositeFeaturePtr& theSketch,
820 if (!theSketch.get() || !PartSet_Tools::sketchPlane(theSketch).get())
823 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
824 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
825 theModes.append(SketcherPrs_Tools::Sel_Constraint);
826 theModes.append(TopAbs_VERTEX);
827 theModes.append(TopAbs_EDGE);
830 Handle(AIS_InteractiveObject) PartSet_SketcherMgr::createPresentation(const ResultPtr& theResult)
832 Handle(AIS_InteractiveObject) aPrs;
834 FeaturePtr aFeature = ModelAPI_Feature::feature(theResult);
835 if (aFeature.get() && aFeature->getKind() == SketchPlugin_Sketch::ID()) {
836 aPrs = new PartSet_ResultSketchPrs(theResult);
841 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
843 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
846 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation) const
848 bool aNestedSketch = false;
850 FeaturePtr anActiveSketch = activeSketch();
851 if (anActiveSketch.get() && theOperation) {
852 ModuleBase_Operation* aSketchOperation = operationMgr()->findOperation(
853 anActiveSketch->getKind().c_str());
854 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
856 if (aSketchOperation && aFOperation) {
857 FeaturePtr aFeature = aFOperation->feature();
858 if (aFeature.get()) {
859 QStringList aGrantedOpIds = aSketchOperation->grantedOperationIds();
860 aNestedSketch = aGrantedOpIds.contains(aFeature->getKind().c_str());
864 return aNestedSketch;
867 bool PartSet_SketcherMgr::isNestedSketchFeature(const QString& theFeatureKind) const
869 bool aNestedSketch = false;
871 FeaturePtr anActiveSketch = activeSketch();
872 if (anActiveSketch.get()) {
873 ModuleBase_Operation* aSketchOperation = operationMgr()->findOperation(
874 anActiveSketch->getKind().c_str());
875 if (aSketchOperation) {
876 QStringList aGrantedOpIds = aSketchOperation->grantedOperationIds();
877 aNestedSketch = aGrantedOpIds.contains(theFeatureKind);
880 return aNestedSketch;
883 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation,
884 const CompositeFeaturePtr& theSketch) const
886 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
888 return aFOperation && !aFOperation->isEditOperation() &&
889 isNestedSketchOperation(aFOperation);
892 bool PartSet_SketcherMgr::isNestedEditOperation(ModuleBase_Operation* theOperation,
893 const CompositeFeaturePtr& theSketch) const
895 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
897 return aFOperation && aFOperation->isEditOperation() &&
898 isNestedSketchOperation(aFOperation);
901 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
903 return (theId == SketchPlugin_Line::ID()) ||
904 (theId == SketchPlugin_Point::ID()) ||
905 (theId == SketchPlugin_Arc::ID()) ||
906 (theId == SketchPlugin_Circle::ID());
909 bool PartSet_SketcherMgr::isExternalFeature(const FeaturePtr& theFeature)
911 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
912 std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
913 return aSPFeature.get() && aSPFeature->isExternal();
916 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
918 std::string anId = theOperation ? theOperation->id().toStdString() : "";
920 return isDistanceKind(anId);
923 bool PartSet_SketcherMgr::isDistanceKind(std::string& theKind)
925 return (theKind == SketchPlugin_ConstraintLength::ID()) ||
926 (theKind == SketchPlugin_ConstraintDistance::ID()) ||
927 (theKind == SketchPlugin_ConstraintRadius::ID()) ||
928 (theKind == SketchPlugin_ConstraintAngle::ID()) ||
929 (theKind == SketchPlugin_ConstraintDistanceHorizontal::ID()) ||
930 (theKind == SketchPlugin_ConstraintDistanceVertical::ID()) ||
931 (theKind == SketchPlugin_ConstraintDistanceAlongDir::ID());
934 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
936 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
937 (getCurrentOperation());
941 myModule->onViewTransformed();
943 // Display all sketcher sub-Objects
944 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
945 mySketchPlane->createSketchPlane(myCurrentSketch, myModule->workshop());
946 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
948 // Hide sketcher result
949 std::list<ResultPtr> aResults = myCurrentSketch->results();
950 std::list<ResultPtr>::const_iterator aIt;
951 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
952 (*aIt)->setDisplayed(false);
954 myCurrentSketch->setDisplayed(false);
956 // Remove invalid sketch entities
957 std::set<FeaturePtr> anInvalidFeatures;
958 ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
959 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
960 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
961 if (aFeature.get()) {
962 if (!aFactory->validate(aFeature))
963 anInvalidFeatures.insert(aFeature);
966 if (!anInvalidFeatures.empty()) {
967 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
968 ModelAPI_Tools::findAllReferences(anInvalidFeatures, aReferences, false);
970 std::set<FeaturePtr>::const_iterator anIt = anInvalidFeatures.begin(),
971 aLast = anInvalidFeatures.end();
972 // separate features to references to parameter features and references to others
973 QStringList anInvalidFeatureNames;
974 for (; anIt != aLast; anIt++) {
975 FeaturePtr aFeature = *anIt;
977 anInvalidFeatureNames.append(aFeature->name().c_str());
979 std::string aPrefixInfo = QString("Invalid features of the sketch will be deleted: %1.\n\n").
980 arg(anInvalidFeatureNames.join(", ")).toStdString().c_str();
981 std::set<FeaturePtr> aFeatureRefsToDelete;
982 if (ModuleBase_Tools::askToDelete(anInvalidFeatures, aReferences, aConnector->desktop(),
983 aFeatureRefsToDelete, aPrefixInfo)) {
984 if (!aFeatureRefsToDelete.empty())
985 anInvalidFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
986 ModelAPI_Tools::removeFeatures(anInvalidFeatures, true);
987 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
988 // TODO: call the next method in the XGUI_OperationMgr::onOperationStarted().
989 workshop()->errorMgr()->updateAcceptAllAction(myCurrentSketch);
993 // update state of overconstraint listener should be done before sketch features/results
994 // display (as the display will ask custom color from the listener)
995 myModule->overconstraintListener()->setActive(true);
996 // Display sketcher objects
998 Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
999 const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
1000 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1001 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1002 #ifdef DEBUG_SKETCHER_ENTITIES
1003 anInfo.append(ModuleBase_Tools::objectInfo(aFeature));
1005 std::list<ResultPtr> aResults = aFeature->results();
1006 std::list<ResultPtr>::const_iterator aIt;
1007 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1008 if ((*aIt)->isDisplayed())
1009 // Display object if it was created outside of GUI
1010 aECreator->sendUpdated((*aIt), EVENT_DISP);
1012 (*aIt)->setDisplayed(true);
1014 if (aFeature->isDisplayed())
1015 aECreator->sendUpdated(aFeature, EVENT_DISP);
1017 aFeature->setDisplayed(true);
1019 #ifdef DEBUG_SKETCHER_ENTITIES
1020 QString anInfoStr = anInfo.join(";\t");
1021 qDebug(QString("startSketch: %1, %2").arg(anInfo.size()).arg(anInfoStr).toStdString().c_str());
1024 bool aHasPlane = false;
1025 std::shared_ptr<GeomAPI_Pln> aPln;
1026 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
1027 Handle(SelectMgr_Filter) aFilter = myModule->selectionFilter(SF_SketchPlaneFilter);
1028 if (!aFilter.IsNull())
1029 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(aPln);
1031 workshop()->selectionActivate()->updateSelectionFilters();
1032 workshop()->selectionActivate()->updateSelectionModes();
1034 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1036 myExternalPointsMgr = new PartSet_ExternalPointsMgr(myModule->workshop(), myCurrentSketch);
1039 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
1041 myIsMouseOverWindow = false;
1042 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
1043 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
1044 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
1046 if (myExternalPointsMgr) {
1047 delete myExternalPointsMgr;
1048 myExternalPointsMgr = 0;
1051 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
1053 DataPtr aData = myCurrentSketch->data();
1054 if (!aData->isValid()) {
1055 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1056 // The sketch was aborted
1057 myCurrentSketch = CompositeFeaturePtr();
1058 mySketchPlane->eraseSketchPlane(myModule->workshop());
1060 // Erase all sketcher objects
1061 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1062 foreach (ObjectPtr aObj, aObjects) {
1063 DataPtr aObjData = aObj->data();
1064 if (!aObjData->isValid())
1065 aObj->setDisplayed(false);
1069 // Hide all sketcher sub-Objects
1070 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1071 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1072 std::list<ResultPtr> aResults = aFeature->results();
1073 std::list<ResultPtr>::const_iterator aIt;
1074 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1075 (*aIt)->setDisplayed(false);
1077 aFeature->setDisplayed(false);
1079 // Display sketcher result
1080 std::list<ResultPtr> aResults = myCurrentSketch->results();
1081 std::list<ResultPtr>::const_iterator aIt;
1082 Events_Loop* aLoop = Events_Loop::loop();
1083 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1085 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1087 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1088 if (!aFOperation->isDisplayedOnStart(*aIt)) {
1089 (*aIt)->setDisplayed(true);
1090 // this display event is needed because sketch already may have "displayed" state,
1091 // but not displayed while it is still active (issue 613, abort of existing sketch)
1092 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
1095 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
1096 myCurrentSketch->setDisplayed(true);
1098 myCurrentSketch = CompositeFeaturePtr();
1099 mySketchPlane->eraseSketchPlane(myModule->workshop());
1101 Events_Loop::loop()->flush(aDispEvent);
1103 workshop()->selectionActivate()->updateSelectionFilters();
1104 workshop()->selectionActivate()->updateSelectionModes();
1107 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
1109 if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
1110 QCursor* aCurrentCursor = QApplication::overrideCursor();
1111 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
1112 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
1114 qDebug("startNestedSketch() : Qt::CrossCursor");
1120 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
1122 myIsMouseOverViewProcessed = true;
1123 operationMgr()->onValidateOperation();
1124 // when sketch nested operation is stopped the cursor should be restored unconditionally
1125 //if (canChangeCursor(theOperation)) {
1126 QApplication::restoreOverrideCursor();
1128 qDebug("stopNestedSketch() : None");
1131 /// improvement to deselect automatically all eventual selected objects, when
1132 // returning to the neutral point of the Sketcher
1133 bool isClearSelectionPossible = true;
1134 if (myIsEditLaunching) {
1135 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1138 FeaturePtr aFeature = aFOperation->feature();
1139 if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
1140 isClearSelectionPossible = false;
1144 if (isClearSelectionPossible)
1145 workshop()->selector()->clearSelection();
1148 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
1150 if (isNestedCreateOperation(theOperation, activeSketch())) {
1151 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1154 FeaturePtr aFeature = aFOperation->feature();
1155 // it is necessary to check the the feature data validity because
1156 // some kind of features are removed by an operation commit(the macro state of a feature)
1157 if (aFeature.get() && aFeature->data()->isValid()) {
1158 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
1164 bool PartSet_SketcherMgr::sketchSelectionFilter(const XGUI_SelectionFilterType theFilterType)
1166 return mySelectionFilterTypes.find(theFilterType) != mySelectionFilterTypes.end();
1169 void PartSet_SketcherMgr::registerSelectionFilter(const XGUI_SelectionFilterType theFilterType,
1170 const Handle(SelectMgr_Filter)& theFilter)
1172 mySelectionFilterTypes.insert(theFilterType);
1173 myModule->registerSelectionFilter(theFilterType, theFilter);
1176 bool PartSet_SketcherMgr::operationActivatedByPreselection()
1178 bool isOperationStopped = false;
1179 ModuleBase_Operation* anOperation = getCurrentOperation();
1180 if(anOperation && isNestedSketchOperation(anOperation)) {
1181 // Set final definitions if they are necessary
1182 //propertyPanelDefined(aOperation);
1183 /// Commit sketcher operations automatically
1184 /// distance operation are able to show popup editor to modify the distance value
1185 /// after entering the value, the operation should be committed/aborted(by Esc key)
1186 bool aCanCommitOperation = true;
1187 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1189 if (aFOperation && PartSet_SketcherMgr::isDistanceOperation(aFOperation)) {
1190 bool aValueAccepted = setDistanceValueByPreselection(anOperation, myModule->workshop(),
1191 aCanCommitOperation);
1192 if (!aValueAccepted)
1193 return isOperationStopped;
1196 if (aCanCommitOperation)
1197 isOperationStopped = anOperation->commit();
1199 anOperation->abort();
1200 isOperationStopped = true;
1203 return isOperationStopped;
1206 bool PartSet_SketcherMgr::canUndo() const
1208 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1211 bool PartSet_SketcherMgr::canRedo() const
1213 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1216 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1218 bool aCanErase = true;
1219 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1220 if (myCurrentSketch.get()) {
1221 return !isObjectOfSketch(theObject);
1226 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1228 bool aCanDisplay = true;
1230 bool aHasActiveSketch = activeSketch().get() != NULL;
1231 if (aHasActiveSketch) {
1232 // 1. the sketch feature should not be displayed during the sketch active operation
1233 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1234 // nested features can be visualized
1235 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1236 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1237 aCanDisplay = false;
1239 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1240 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1241 /// some sketch entities should be never shown, e.g. projection feature
1242 if (aSketchFeature.get())
1243 aCanDisplay = aSketchFeature->canBeDisplayed();
1245 else { // there are no an active sketch
1246 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1247 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1248 if (aFeature.get() != NULL) {
1249 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1250 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1251 if (aSketchFeature.get()) {
1252 aCanDisplay = false;
1257 // 3. the method should not filter the objects, which are not related to the current operation.
1258 // The object is filtered just if it is a current operation feature or this feature result
1260 bool isObjectFound = false;
1261 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1262 (getCurrentOperation());
1264 FeaturePtr aFeature = aFOperation->feature();
1265 if (aFeature.get()) {
1266 std::list<ResultPtr> aResults = aFeature->results();
1267 if (theObject == aFeature)
1268 isObjectFound = true;
1270 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1271 for (; anIt != aLast && !isObjectFound; anIt++) {
1272 isObjectFound = *anIt == theObject;
1277 if (isObjectFound) {
1278 // 4. For created nested feature operation do not display the created feature if
1279 // the mouse curstor leaves the OCC window.
1280 // The correction cases, which ignores this condition:
1281 // a. the property panel values modification
1282 // b. the popup menu activated
1283 // c. widget editor control
1284 #ifndef DEBUG_DO_NOT_BY_ENTER
1285 if (isNestedCreateOperation(getCurrentOperation(), activeSketch())) {
1286 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1287 ModuleBase_WidgetEditor* anEditorWdg =
1288 anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1289 // the active widget editor should not influence here. The presentation should be visible
1290 // always when this widget is active.
1291 if (!anEditorWdg && !myIsPopupMenuActive) {
1292 // during a nested create operation, the feature is redisplayed only
1293 // if the mouse over view
1294 // of there was a value modified in the property panel after the mouse left the view
1295 aCanDisplay = canDisplayCurrentCreatedFeature();
1302 // checks the sketcher constraints visibility according to active sketch check box states
1304 bool aProcessed = false;
1305 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1306 if (aFeature.get()) {
1307 bool aConstraintDisplayed = canDisplayConstraint(aFeature, PartSet_Tools::Any, aProcessed);
1309 aCanDisplay = aConstraintDisplayed;
1316 bool PartSet_SketcherMgr::canDisplayConstraint(const FeaturePtr& theFeature,
1317 const PartSet_Tools::ConstraintVisibleState& theState,
1318 bool& isProcessed) const
1320 bool aSwitchedOn = true;
1322 const QStringList& aConstrIds = constraintsIdList();
1324 std::string aKind = theFeature->getKind();
1325 if (aConstrIds.contains(QString(aKind.c_str()))) {
1326 bool isTypedConstraint = false;
1329 case PartSet_Tools::Dimensional: {
1330 bool isDistance = isDistanceKind(aKind);
1333 aSwitchedOn = myIsConstraintsShown[theState];
1337 case PartSet_Tools::Geometrical: {
1338 bool isGeometrical = !isDistanceKind(aKind);
1339 if (isGeometrical) {
1341 aSwitchedOn = myIsConstraintsShown[theState];
1345 case PartSet_Tools::Any: {
1347 bool isDistance = isDistanceKind(aKind);
1349 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Dimensional];
1351 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Geometrical];
1361 /*void PartSet_SketcherMgr::processHiddenObject(const std::list<ObjectPtr>& theObjects)
1363 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1364 (getCurrentOperation());
1365 if (aFOperation && myCurrentSketch.get()) {
1366 // find results of the current operation
1367 // these results should not be proposed to be deleted
1368 FeaturePtr anOperationFeature = aFOperation->feature();
1369 std::list<ResultPtr> anOperationResultList = anOperationFeature->results();
1370 std::set<ResultPtr> anOperationResults;
1371 std::list<ResultPtr>::const_iterator aRIt = anOperationResultList.begin(),
1372 aRLast = anOperationResultList.end();
1373 for (; aRIt != aRLast; aRIt++)
1374 anOperationResults.insert(*aRIt);
1376 std::set<FeaturePtr> anObjectsToBeDeleted;
1377 QStringList anObjectsToBeDeletedNames;
1378 std::list<ObjectPtr>::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1379 for (; anIt != aLast; anIt++) {
1380 ObjectPtr anObject = *anIt;
1381 bool aCanErase = true;
1382 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1383 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1384 // the result is found between current feature results
1385 if (anOperationResults.find(aResult) != anOperationResults.end())
1388 if (aResult.get()) {
1389 // Display sketcher objects
1390 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1391 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1392 std::list<ResultPtr> aResults = aFeature->results();
1393 std::list<ResultPtr>::const_iterator anIt;
1394 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1395 aCanErase = *anIt != aResult;
1400 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1401 if (aFeature.get() && anObjectsToBeDeleted.find(aFeature) == anObjectsToBeDeleted.end()) {
1402 anObjectsToBeDeleted.insert(aFeature);
1403 anObjectsToBeDeletedNames.append(aFeature->name().c_str());
1407 if (!anObjectsToBeDeleted.empty()) {
1408 QString aFeatureNames = anObjectsToBeDeletedNames.join(", ");
1409 QString aMessage = tr("The following features have incorrect presentation and \
1410 will be hidden: %1. Would you like to delete them?")
1411 .arg(aFeatureNames);
1412 int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Features hide"),
1413 aMessage, QMessageBox::Ok | QMessageBox::Cancel,
1414 QMessageBox::Cancel);
1415 if (anAnswer == QMessageBox::Ok) {
1416 QObjectPtrList anObjects;
1417 std::set<FeaturePtr>::const_iterator anIt = anObjectsToBeDeleted.begin(),
1418 aLast = anObjectsToBeDeleted.end();
1419 for (; anIt != aLast; anIt++)
1420 anObjects.append(*anIt);
1421 SessionPtr aMgr = ModelAPI_Session::get();
1422 DocumentPtr aDoc = aMgr->activeDocument();
1423 bool aIsOp = aMgr->isOperation();
1425 aMgr->startOperation();
1426 workshop()->deleteFeatures(anObjects);
1427 //static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
1428 //static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
1429 //Events_Loop::loop()->flush(aDeletedEvent);
1430 //Events_Loop::loop()->flush(aRedispEvent);
1433 aMgr->finishOperation();
1439 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1441 bool aCanDisplay = myIsMouseOverWindow;
1443 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1445 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1450 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1452 return isNestedCreateOperation(theOperation, activeSketch()) ||
1453 myModule->sketchReentranceMgr()->isInternalEditActive();
1456 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
1458 return myIsConstraintsShown;
1461 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1463 bool isFoundObject = false;
1465 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1466 if (anObjectFeature.get()) {
1467 int aSize = myCurrentSketch->numberOfSubs();
1468 for (int i = 0; i < myCurrentSketch->numberOfSubs() && !isFoundObject; i++) {
1469 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1470 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1473 return isFoundObject;
1476 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePlane)
1478 Handle(SelectMgr_Filter) aFilter = myModule->selectionFilter(SF_SketchPlaneFilter);
1479 if (!aFilter.IsNull())
1480 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(thePlane);
1482 workshop()->selectionActivate()->updateSelectionModes();
1485 bool PartSet_SketcherMgr::setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
1486 ModuleBase_IWorkshop* theWorkshop,
1487 bool& theCanCommitOperation)
1489 bool isValueAccepted = false;
1490 theCanCommitOperation = false;
1492 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1494 FeaturePtr aFeature = aFOperation->feature();
1495 // editor is shown only if all attribute references are filled by preseletion
1496 bool anAllRefAttrInitialized = true;
1498 std::list<AttributePtr> aRefAttrs = aFeature->data()->attributes(
1499 ModelAPI_AttributeRefAttr::typeId());
1500 std::list<AttributePtr>::const_iterator anIt = aRefAttrs.begin(), aLast = aRefAttrs.end();
1501 for (; anIt != aLast && anAllRefAttrInitialized; anIt++) {
1502 anAllRefAttrInitialized = (*anIt)->isInitialized();
1504 if (anAllRefAttrInitialized) {
1505 // Activate dimension value editing on double click
1506 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
1507 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
1508 // Find corresponded widget to activate value editing
1509 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
1510 if (aWgt->attributeID() == "ConstraintValue") {
1511 // the featue should be displayed in order to find the AIS text position,
1512 // the place where the editor will be shown
1513 aFeature->setDisplayed(true);
1514 /// the execute is necessary to perform in the feature compute for flyout position
1515 aFeature->execute();
1517 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1518 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1520 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
1522 int aX = 0, anY = 0;
1524 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(theWorkshop);
1525 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1526 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
1527 Handle(AIS_InteractiveObject) anAISIO;
1528 if (anAIS.get() != NULL) {
1529 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1531 if (anAIS.get() != NULL) {
1532 Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1534 if (!anAISIO.IsNull()) {
1535 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
1536 if (!aDim.IsNull()) {
1537 gp_Pnt aPosition = aDim->GetTextPosition();
1539 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
1540 Handle(V3d_View) aView = aViewer->activeView();
1542 aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
1544 QWidget* aViewPort = aViewer->activeViewPort();
1545 QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
1550 anEditor->setCursorPosition(aX, anY);
1551 isValueAccepted = anEditor->showPopupEditor(false);
1552 theCanCommitOperation = true;
1558 return isValueAccepted;
1561 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1562 const FeaturePtr& theSketch,
1563 ModuleBase_IWorkshop* theWorkshop,
1564 const FeatureToSelectionMap& theSelection,
1565 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1567 if (theFeature.get() == NULL)
1570 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1571 SelectionInfo anInfo = anIt.value();
1572 std::set<AttributePtr> aSelectedAttributes = anInfo.myAttributes;
1573 std::set<ResultPtr> aSelectedResults = anInfo.myResults;
1575 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1577 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1578 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1580 // 1. found the feature's owners. Check the AIS objects of the constructions
1581 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1582 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1583 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1585 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1586 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1587 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1588 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1589 if (!anOwner.IsNull())
1590 theOwnersToSelect.Add(anOwner);
1594 // 2. found the feature results's owners
1595 std::list<ResultPtr> aResults = theFeature->results();
1596 std::list<ResultPtr>::const_iterator aIt;
1598 bool isSameShape = false;
1599 if (aResults.size() > 0) {
1600 ResultPtr aFirstResult = theFeature->firstResult();
1601 if (aFirstResult.get() && aFirstResult->shape().get()) {
1602 TopoDS_Shape aFirstShape = aFirstResult->shape()->impl<TopoDS_Shape>();
1603 isSameShape = aFirstShape.IsEqual(anInfo.myFirstResultShape);
1606 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1607 ResultPtr aResult = *aIt;
1608 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1609 if (aAISObj.get() == NULL)
1611 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1613 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1614 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1615 bool aFoundLocalShape = false;
1616 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1617 Handle(StdSelect_BRepOwner) anOwner =
1618 Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1619 if ( anOwner.IsNull() || !anOwner->HasShape() || theOwnersToSelect.FindIndex(anOwner))
1621 const TopoDS_Shape& aShape = anOwner->Shape();
1622 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1623 if (aShapeType == TopAbs_VERTEX) {
1624 AttributePtr aPntAttr =
1625 PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1626 if (aPntAttr.get() != NULL &&
1627 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end())
1628 theOwnersToSelect.Add(anOwner);
1629 else if (isSameShape && anInfo.myLocalSelectedShapes.Contains(aShape)) {
1630 theOwnersToSelect.Add(anOwner);
1633 else if (aShapeType == TopAbs_EDGE) {
1634 if (isSameShape && anInfo.myLocalSelectedShapes.Contains(aShape)) {
1635 // try to restore local selection on Shape result
1636 // we can do this only if the shape was not changed
1637 theOwnersToSelect.Add(anOwner);
1638 aFoundLocalShape = true;
1643 if (!aFoundLocalShape) {
1644 // result owners are put in the list of selection only if local selected shapes were not
1646 if (aSelectedResults.find(aResult) != aSelectedResults.end()) {
1647 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1648 Handle(StdSelect_BRepOwner) anOwner =
1649 Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1650 if ( anOwner.IsNull() || !anOwner->HasShape() || theOwnersToSelect.FindIndex(anOwner))
1652 // select whole result
1653 theOwnersToSelect.Add(anOwner);
1660 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
1661 const bool isToConnect)
1663 //Temporary commented as we do not modify values in property panel
1665 //connect(theWidget, SIGNAL(beforeValuesChanged()),
1666 // this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1667 //connect(theWidget, SIGNAL(afterValuesChanged()),
1668 // this, SLOT(onAfterValuesChangedInPropertyPanel()));
1669 connect(theWidget, SIGNAL(afterValuesChanged()),
1670 myModule->sketchReentranceMgr(), SLOT(onAfterValuesChangedInPropertyPanel()));
1673 //disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1674 // this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1675 //disconnect(theWidget, SIGNAL(afterValuesChanged()),
1676 // this, SLOT(onAfterValuesChangedInPropertyPanel()));
1677 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1678 myModule->sketchReentranceMgr(), SLOT(onAfterValuesChangedInPropertyPanel()));
1682 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1684 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1685 (getCurrentOperation());
1687 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1688 isNestedSketchOperation(aFOperation) &&
1689 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1690 FeaturePtr aFeature = aFOperation->feature();
1691 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1696 void PartSet_SketcherMgr::customizePresentation(const ObjectPtr& theObject)
1698 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1699 (getCurrentOperation());
1700 if (aFOperation && (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1701 isNestedSketchOperation(aFOperation)))
1702 SketcherPrs_Tools::sendExpressionShownEvent(myIsConstraintsShown[PartSet_Tools::Expressions]);
1704 // update entities selection priorities
1705 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1706 if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
1707 // update priority for feature
1708 updateSelectionPriority(aFeature, aFeature);
1709 // update priority for results of the feature
1710 std::list<ResultPtr> aResults = aFeature->results();
1711 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLastIt = aResults.end();
1712 for (; anIt != aLastIt; anIt++)
1713 updateSelectionPriority(*anIt, aFeature);
1717 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1719 return myModule->workshop()->currentOperation();
1722 //**************************************************************
1723 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1725 ModuleBase_ModelWidget* aWidget = 0;
1726 ModuleBase_Operation* anOperation = getCurrentOperation();
1728 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1730 aWidget = aPanel->activeWidget();
1735 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1736 const bool isEditOperation,
1737 const bool isToDisplay,
1738 const bool isFlushRedisplay)
1740 #ifdef DEBUG_DO_NOT_BY_ENTER
1744 if (isEditOperation || !theFeature.get())
1747 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1748 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1750 // 1. change visibility of the object itself, here the presentable object is processed,
1751 // e.g. constraints features
1752 //FeaturePtr aFeature = aFOperation->feature();
1753 std::list<ResultPtr> aResults = theFeature->results();
1755 theFeature->setDisplayed(true);
1757 theFeature->setDisplayed(false);
1759 // change visibility of the object results, e.g. non-constraint features
1760 std::list<ResultPtr>::const_iterator aIt;
1761 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1763 (*aIt)->setDisplayed(true);
1766 (*aIt)->setDisplayed(false);
1769 if (isFlushRedisplay)
1770 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1773 void PartSet_SketcherMgr::storeSelection(const SelectionType theType,
1774 PartSet_SketcherMgr::FeatureToSelectionMap& theCurrentSelection)
1776 if (!myCurrentSketch.get())
1779 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1780 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1781 QList<ModuleBase_ViewerPrsPtr> aStoredPrs;
1783 if (theType == ST_HighlightType || theType == ST_SelectAndHighlightType)
1784 aStoredPrs = aSelect->getHighlighted();
1786 QList<FeaturePtr> aFeatureList;
1787 if (theType == ST_SelectAndHighlightType || theType == ST_SelectType) {
1788 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected(
1789 ModuleBase_ISelection::AllControls);
1790 aStoredPrs.append(aSelected);
1793 // 1. it is necessary to save current selection in order to restore it after the features moving
1794 theCurrentSelection.clear();
1796 QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = aStoredPrs.begin(),
1797 aLast = aStoredPrs.end();
1799 CompositeFeaturePtr aSketch = activeSketch();
1800 for (; anIt != aLast; anIt++) {
1801 ModuleBase_ViewerPrsPtr aPrs = *anIt;
1802 ObjectPtr anObject = aPrs->object();
1803 if (!anObject.get())
1806 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1807 FeaturePtr aFeature;
1809 aFeature = ModelAPI_Feature::feature(aResult);
1811 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1813 if (!aFeature.get())
1816 std::set<AttributePtr> aSelectedAttributes;
1817 std::set<ResultPtr> aSelectedResults;
1818 SelectionInfo anInfo;
1819 if (theCurrentSelection.find(aFeature) != theCurrentSelection.end())
1820 anInfo = theCurrentSelection.find(aFeature).value();
1822 TopoDS_Shape aFirstShape;
1823 ResultPtr aFirstResult = aFeature->firstResult();
1824 if (aFirstResult.get() && aFirstResult->shape().get())
1825 aFirstShape = aFirstResult->shape()->impl<TopoDS_Shape>();
1826 anInfo.myFirstResultShape = aFirstShape;
1827 Handle(SelectMgr_EntityOwner) anOwner = aPrs->owner();
1828 if (aResult.get()) {
1829 getAttributesOrResults(anOwner, aFeature, aSketch, aResult,
1830 anInfo.myAttributes, anInfo.myResults, anInfo.myLocalSelectedShapes);
1833 std::list<ResultPtr> aResults = aFeature->results();
1834 std::list<ResultPtr>::const_iterator aIt;
1835 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1836 ResultPtr aResult = *aIt;
1837 getAttributesOrResults(anOwner, aFeature, aSketch, aResult,
1838 anInfo.myAttributes, anInfo.myResults, anInfo.myLocalSelectedShapes);
1841 theCurrentSelection[aFeature] = anInfo;
1843 //qDebug(QString(" storeSelection: %1").arg(theCurrentSelection.size()).toStdString().c_str());
1846 void PartSet_SketcherMgr::restoreSelection(
1847 PartSet_SketcherMgr::FeatureToSelectionMap& theCurrentSelection)
1849 if (!myCurrentSketch.get())
1852 //qDebug(QString("restoreSelection: %1").arg(theCurrentSelection.size()).toStdString().c_str());
1853 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1854 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1855 FeatureToSelectionMap::const_iterator aSIt = theCurrentSelection.begin(),
1856 aSLast = theCurrentSelection.end();
1857 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1858 anOwnersToSelect.Clear();
1859 for (; aSIt != aSLast; aSIt++) {
1860 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, theCurrentSelection,
1863 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1866 void PartSet_SketcherMgr::onShowConstraintsToggle(int theType, bool theState)
1868 PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
1870 updateBySketchParameters(aType, theState);
1873 void PartSet_SketcherMgr::updateBySketchParameters(
1874 const PartSet_Tools::ConstraintVisibleState& theType,
1877 if (myCurrentSketch.get() == NULL)
1880 bool aPrevState = myIsConstraintsShown[theType];
1881 myIsConstraintsShown[theType] = theState;
1884 case PartSet_Tools::Geometrical:
1885 case PartSet_Tools::Dimensional: {
1886 if (aPrevState != theState) {
1887 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1888 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1889 for (int i = 0; i < myCurrentSketch->numberOfSubs(); i++) {
1890 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1891 bool aProcessed = false;
1892 bool aConstraintDisplayed = canDisplayConstraint(aSubFeature, theType, aProcessed);
1894 aSubFeature->setDisplayed(aConstraintDisplayed);
1896 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1900 case PartSet_Tools::Expressions: {
1901 if (aPrevState != theState) {
1902 /// call all sketch features redisplay, the expression state will be corrected in customize
1903 /// of distance presentation
1904 Events_ID anEventId = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1905 PartSet_Tools::sendSubFeaturesEvent(myCurrentSketch, anEventId);
1912 void PartSet_SketcherMgr::updateSelectionPriority(ObjectPtr theObject,
1913 FeaturePtr theFeature)
1915 if (!theObject.get() || !theFeature.get())
1918 AISObjectPtr anAIS = workshop()->displayer()->getAISObject(theObject);
1919 Handle(AIS_InteractiveObject) anAISIO;
1920 if (anAIS.get() != NULL) {
1921 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1924 if (!anAISIO.IsNull()) { // the presentation for the object is visualized
1925 int anAdditionalPriority = 0;
1927 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
1928 std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
1929 if (aSPFeature.get() != NULL) {
1931 // 2. Simple segments
1932 // 3. External objects (violet color)
1933 // 4. Auxiliary segments (dotted)
1934 // StdSelect_BRepSelectionTool::Load uses priority calculating:
1935 // Standard_Integer aPriority =
1936 // (thePriority == -1) ? GetStandardPriority (theShape, theType) : thePriority;
1937 // Priority of Vertex is 8, edge(segment) is 7.
1938 // It might be not corrected as provides the condition above.
1939 bool isExternal = aSPFeature->isExternal();
1940 bool isAuxiliary = PartSet_Tools::isAuxiliarySketchEntity(aSPFeature);
1942 if (!isExternal && !isAuxiliary)
1943 anAdditionalPriority = 30;
1946 anAdditionalPriority = 20;
1947 // auxiliary feature
1949 anAdditionalPriority = 10; /// auxiliary objects should have less priority that
1950 // edges/vertices of local selection on not-sketch objects
1952 Handle(ModuleBase_ResultPrs) aResult = Handle(ModuleBase_ResultPrs)::DownCast(anAISIO);
1953 if (!aResult.IsNull()) {
1954 aResult->setAdditionalSelectionPriority(anAdditionalPriority);
1960 XGUI_Workshop* PartSet_SketcherMgr::workshop() const
1962 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
1963 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
1964 return aConnector->workshop();
1967 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
1969 return workshop()->operationMgr();