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 <GeomAPI_Shape.h>
66 #include <Events_Loop.h>
68 #include <SketchPlugin_Line.h>
69 #include <SketchPlugin_Sketch.h>
70 #include <SketchPlugin_Point.h>
71 #include <SketchPlugin_Arc.h>
72 #include <SketchPlugin_Circle.h>
73 #include <SketchPlugin_ConstraintLength.h>
74 #include <SketchPlugin_ConstraintDistance.h>
75 #include <SketchPlugin_ConstraintParallel.h>
76 #include <SketchPlugin_ConstraintPerpendicular.h>
77 #include <SketchPlugin_ConstraintRadius.h>
78 #include <SketchPlugin_ConstraintRigid.h>
79 #include <SketchPlugin_ConstraintHorizontal.h>
80 #include <SketchPlugin_ConstraintVertical.h>
81 #include <SketchPlugin_ConstraintEqual.h>
82 #include <SketchPlugin_ConstraintTangent.h>
83 #include <SketchPlugin_ConstraintCoincidence.h>
84 #include <SketchPlugin_Fillet.h>
85 #include <SketchPlugin_ConstraintMirror.h>
86 #include <SketchPlugin_ConstraintAngle.h>
87 #include <SketchPlugin_ConstraintCollinear.h>
88 #include <SketchPlugin_ConstraintMiddle.h>
89 #include <SketchPlugin_MultiRotation.h>
90 #include <SketchPlugin_MultiTranslation.h>
91 #include <SketchPlugin_IntersectionPoint.h>
92 #include <SketchPlugin_Projection.h>
93 #include <SketchPlugin_ConstraintDistanceAlongDir.h>
94 #include <SketchPlugin_ConstraintDistanceHorizontal.h>
95 #include <SketchPlugin_ConstraintDistanceVertical.h>
97 #include <SketcherPrs_Tools.h>
99 #include <SelectMgr_IndexedMapOfOwner.hxx>
100 #include <StdSelect_BRepOwner.hxx>
102 //#include <AIS_DimensionSelectionMode.hxx>
103 #include <AIS_Shape.hxx>
104 #include <AIS_Dimension.hxx>
106 #include <ModelAPI_Events.h>
107 #include <ModelAPI_Session.h>
108 #include <ModelAPI_AttributeString.h>
110 #include <ModelAPI_Validator.h>
111 #include <ModelAPI_Tools.h>
113 #include <QMouseEvent>
114 #include <QApplication>
116 #include <QMessageBox>
117 #include <QMainWindow>
119 //#define DEBUG_DO_NOT_BY_ENTER
120 //#define DEBUG_SKETCHER_ENTITIES
121 //#define DEBUG_SKETCH_ENTITIES_ON_MOVE
122 //#define DRAGGING_DEBUG
123 //#define DEBUG_CURSOR
126 #ifdef DRAGGING_DEBUG
130 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
131 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge,
132 /// put the function result as is to the list of results.
133 /// \param theOwner a viewer selected owner
134 /// \param theFeature a feature, where the attribute is searched
135 /// \param theSketch a current sketch
136 /// \param theSelectedAttribute an output list of attributes
137 /// \param theSelectedResults an output list of edge results
138 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
139 const FeaturePtr& theFeature, const FeaturePtr& theSketch,
140 const ResultPtr& theResult,
141 std::set<AttributePtr>& theSelectedAttributes,
142 std::set<ResultPtr>& theSelectedResults,
143 TopTools_MapOfShape& theShapes)
145 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
146 if (aBRepOwner.IsNull())
148 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
149 aBRepOwner->Selectable());
150 if (aBRepOwner->HasShape()) {
151 const TopoDS_Shape& aShape = aBRepOwner->Shape();
152 theShapes.Add(aShape);
153 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
154 if (aShapeType == TopAbs_VERTEX) {
155 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
157 if (aPntAttr.get() != NULL)
158 theSelectedAttributes.insert(aPntAttr);
160 else if (aShapeType == TopAbs_EDGE &&
161 theSelectedResults.find(theResult) == theSelectedResults.end()) {
162 theSelectedResults.insert(theResult);
167 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
168 : QObject(theModule), myModule(theModule), myIsEditLaunching(false), myIsDragging(false),
169 myDragDone(false), myIsMouseOverWindow(false),
170 myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
171 myIsPopupMenuActive(false), myExternalPointsMgr(0)
173 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
174 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
176 myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
178 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
179 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
181 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
182 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
184 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
185 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
187 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
188 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
190 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
191 XGUI_Workshop* aWorkshop = aConnector->workshop();
192 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
194 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
195 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
196 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
198 mySketchPlane = new PartSet_PreviewSketchPlane();
200 registerSelectionFilter(SF_SketchCirclePointFilter, new PartSet_CirclePointFilter(anIWorkshop));
201 registerSelectionFilter(SF_SketchPlaneFilter, new ModuleBase_ShapeInPlaneFilter());
204 PartSet_SketcherMgr::~PartSet_SketcherMgr()
206 delete mySketchPlane;
209 void PartSet_SketcherMgr::onEnterViewPort()
211 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
212 // created feature because it should be done in onMouseMove(). Some widgets watch
213 // the mouse move and use the cursor position to update own values. If the presentaion is
214 // redisplayed before this update, the feature presentation jumps from reset value to current.
215 myIsMouseOverWindow = true;
217 #ifdef DEBUG_DO_NOT_BY_ENTER
221 if (canChangeCursor(getCurrentOperation())) {
222 QCursor* aCurrentCursor = QApplication::overrideCursor();
223 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
224 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
226 qDebug("onEnterViewPort() : Qt::CrossCursor");
231 if (!isNestedCreateOperation(getCurrentOperation(), activeSketch()))
234 operationMgr()->onValidateOperation();
236 // we need change displayed state of the current operation feature
237 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
238 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
239 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
240 // presentation becomes valid and redisplay happens
241 //ModuleBase_Operation* aOperation = getCurrentOperation();
242 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
243 (getCurrentOperation());
245 FeaturePtr aFeature = aFOperation->feature();
246 if (aFeature.get() && aFeature->data()->isValid()) {
247 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
252 void PartSet_SketcherMgr::onLeaveViewPort()
254 myIsMouseOverViewProcessed = false;
255 myIsMouseOverWindow = false;
257 #ifdef DEBUG_DO_NOT_BY_ENTER
261 if (canChangeCursor(getCurrentOperation())) {
262 QApplication::restoreOverrideCursor();
264 qDebug("onLeaveViewPort() : None");
268 if (!isNestedCreateOperation(getCurrentOperation(), activeSketch()))
271 // the method should be performed if the popup menu is called,
272 // the reset of the current widget should not happen
273 if (myIsPopupMenuActive)
276 // it is important to validate operation here only if sketch entity create operation is active
277 // because at this operation we reacts to the mouse leave/enter view port
278 operationMgr()->onValidateOperation();
280 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
281 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
282 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
283 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
284 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
285 // obtained after reset value
286 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
287 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
289 anActiveWidget->reset();
291 // hides the presentation of the current operation feature
292 // the feature is to be erased here, but it is correct to call canDisplayObject because
293 // there can be additional check (e.g. editor widget in distance constraint)
294 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
295 (getCurrentOperation());
297 FeaturePtr aFeature = aFOperation->feature();
298 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
300 // we should update viewer after the presentation are hidden in the viewer
301 // otherwise the reset presentation(line) appears in the viewer(by quick move from viewer to PP)
302 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
306 //Temporary commented as we do not modify values in property panel
307 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
309 if (!isNestedEditOperation(getCurrentOperation(), myModule->sketchMgr()->activeSketch()) ||
310 myModule->sketchReentranceMgr()->isInternalEditActive())
312 // it is necessary to save current selection in order to restore it after the values are modifed
313 storeSelection(ST_SelectAndHighlightType);
315 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
316 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
317 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
318 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
321 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
323 if (!isNestedEditOperation(getCurrentOperation(), myModule->sketchMgr()->activeSketch()) ||
324 myModule->sketchReentranceMgr()->isInternalEditActive()) {
325 myModule->sketchReentranceMgr()->updateInternalEditActiveState();
328 // it is necessary to restore current selection in order to restore it after values are modified
330 myCurrentSelection.clear();
332 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
333 // viewer happens by deselect/select the modified objects. The flag should be restored after
334 // the selection processing. The update viewer should be also called.
335 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
336 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
337 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
338 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
339 aDisplayer->updateViewer();
343 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
345 // Clear dragging mode
346 myIsDragging = false;
348 if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
350 //get2dPoint(theWnd, theEvent, myClickedPoint);
351 if (!(theEvent->buttons() & Qt::LeftButton))
354 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
355 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
356 if (!aViewer->canDragByMouse())
359 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
360 (getCurrentOperation());
364 if (aFOperation->isEditOperation()) {
365 // If the current widget is a selector, do nothing, it processes the mouse press
366 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
367 if(anActiveWidget && anActiveWidget->isViewerSelector()) {
372 // Use only for sketch operations
373 if (myCurrentSketch) {
374 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
377 bool isSketcher = isSketchOperation(aFOperation);
378 bool isSketchOpe = isNestedSketchOperation(aFOperation);
380 // Avoid non-sketch operations
381 if ((!isSketchOpe) && (!isSketcher))
384 bool isEditing = aFOperation->isEditOperation();
386 // Ignore creation sketch operation
387 if ((!isSketcher) && (!isEditing))
390 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
391 // Remember highlighted objects for editing
392 ModuleBase_ISelection* aSelect = aWorkshop->selection();
394 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
395 storeSelection(aHasShift ? ST_SelectAndHighlightType : ST_HighlightType, myCurrentSelection);
397 if (myCurrentSelection.empty()) {
398 if (isSketchOpe && (!isSketcher))
399 // commit previous operation
400 if (!aFOperation->commit())
401 aFOperation->abort();
404 // Init flyout point for radius rotation
405 FeaturePtr aFeature = myCurrentSelection.begin().key();
407 get2dPoint(theWnd, theEvent, myCurrentPoint);
412 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
414 if (aFeature.get() != NULL) {
415 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
416 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
417 if (aSPFeature.get() &&
418 (aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID() ||
419 aSPFeature->getKind() == SketchPlugin_ConstraintAngle::ID())) {
420 DataPtr aData = aSPFeature->data();
421 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
422 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
423 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
424 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
427 } else if (isSketchOpe && isEditing) {
428 // If selected another object commit current result
429 bool aPrevLaunchingState = myIsEditLaunching;
430 /// store editing state for Edit operation in order to do not clear highlight by restart
431 /// of edit operation.
432 /// Internal edit should not be stored as editing operation as the result will be a
433 /// creation operation, where previous selection should not be used(and will be cleared)
434 myIsEditLaunching = !myModule->sketchReentranceMgr()->isInternalEditActive();
435 aFOperation->commit();
440 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
442 myIsEditLaunching = aPrevLaunchingState;
443 if (aFeature.get() != NULL) {
444 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
445 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
446 if (aSPFeature.get() &&
447 (aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID() ||
448 aSPFeature->getKind() == SketchPlugin_ConstraintAngle::ID())) {
449 DataPtr aData = aSPFeature->data();
450 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
451 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
452 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
453 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
460 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
462 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
464 aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
466 bool aWasDragging = myIsDragging;
467 myIsDragging = false;
469 if (myModule->sketchReentranceMgr()->processMouseReleased(theWnd, theEvent))
472 // if mouse is pressed when it was over view and at release the mouse is out of view, do nothing
473 if (!myIsMouseOverViewProcessed)
476 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
477 if (!aViewer->canDragByMouse())
479 ModuleBase_Operation* aOp = getCurrentOperation();
481 if (isNestedSketchOperation(aOp)) {
482 // Only for sketcher operations
485 /// the previous selection is lost by mouse release in the viewer(Select method), but
486 /// it is still stored in myCurrentSelection. So, it is possible to restore selection
487 /// It is important for drag(edit with mouse) of sketch entities.
488 restoreSelection(myCurrentSelection);
489 myCurrentSelection.clear();
496 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
497 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
499 aProcessor->mouseReleased(theWnd, theEvent);
502 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
504 #ifdef DEBUG_SKETCH_ENTITIES_ON_MOVE
505 CompositeFeaturePtr aSketch = activeSketch();
507 std::cout << "mouse move SKETCH FEATURES [" << aSketch->numberOfSubs() << "]:" << std::endl;
509 for (int i = 0, aNbSubs = aSketch->numberOfSubs(); i < aNbSubs; i++) {
510 //std::cout << getFeatureInfo(aSketch->subFeature(i), false) << std::endl;
511 anInfo.append(ModuleBase_Tools::objectInfo(aSketch->subFeature(i)));
513 QString anInfoStr = anInfo.join("\n");
514 qDebug(QString("%1").arg(anInfo.size()).arg(anInfoStr).toStdString().c_str());
518 if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
521 if (isNestedCreateOperation(getCurrentOperation(), activeSketch())) {
522 #ifdef DRAGGING_DEBUG
526 // 1. perform the widget mouse move functionality and display the presentation
527 // the mouse move should be processed in the widget, if it can in order to visualize correct
528 // presentation. These widgets correct the feature attribute according to the mouse position
529 ModuleBase_ModelWidget* anActiveWidget = myModule->activeWidget();
530 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
532 aProcessor->mouseMoved(theWnd, theEvent);
533 if (!myIsMouseOverViewProcessed) {
534 myIsMouseOverViewProcessed = true;
536 // the feature is to be erased here, but it is correct to call canDisplayObject because
537 // there can be additional check (e.g. editor widget in distance constraint)
538 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
539 (getCurrentOperation());
541 FeaturePtr aFeature = aFOperation->feature();
542 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
545 #ifdef DRAGGING_DEBUG
546 cout << "Mouse move processing " << t.elapsed() << endl;
549 //myClickedPoint.clear();
552 // 1. the current selection is saved in the mouse press method in order to restore it after
554 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
555 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
556 // deselected). This flag should be restored in the slot, processed the mouse release signal.
558 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
559 if (!aCurrentOperation)
561 if (isSketchOperation(aCurrentOperation))
562 return; // No edit operation activated
564 Handle(V3d_View) aView = theWnd->v3dView();
565 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
567 get2dPoint(theWnd, theEvent, aMousePnt);
569 std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition = std::shared_ptr<GeomAPI_Pnt2d>(
570 new GeomAPI_Pnt2d(myCurrentPoint.myCurX, myCurrentPoint.myCurY));
571 std::shared_ptr<GeomAPI_Pnt2d> aCurrentPosition = std::shared_ptr<GeomAPI_Pnt2d>(
572 new GeomAPI_Pnt2d(aMousePnt.myCurX, aMousePnt.myCurY));
574 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
575 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
576 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
577 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
578 // viewer happens by deselect/select the modified objects. The flag should be restored after
579 // the selection processing. The update viewer should be also called.
580 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
582 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
583 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
584 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
585 aLast = myCurrentSelection.end();
586 // 4. the features and attributes modification(move)
587 bool isModified = false;
588 for (; anIt != aLast; anIt++) {
589 FeaturePtr aFeature = anIt.key();
591 std::set<AttributePtr> anAttributes = anIt.value().myAttributes;
592 // Process selection by attribute: the priority to the attribute
593 if (!anAttributes.empty()) {
594 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
595 anAttLast = anAttributes.end();
596 for (; anAttIt != anAttLast; anAttIt++) {
597 AttributePtr anAttr = *anAttIt;
598 if (anAttr.get() == NULL)
600 std::string aAttrId = anAttr->id();
601 DataPtr aData = aFeature->data();
602 if (aData->isValid()) {
603 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
604 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
605 if (aPoint.get() != NULL) {
606 bool isImmutable = aPoint->setImmutable(true);
608 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage = std::shared_ptr
609 <ModelAPI_ObjectMovedMessage>(new ModelAPI_ObjectMovedMessage(this));
610 aMessage->setMovedAttribute(aPoint);
611 aMessage->setOriginalPosition(anOriginalPosition);
612 aMessage->setCurrentPosition(aCurrentPosition);
613 Events_Loop::loop()->send(aMessage);
616 aPoint->setImmutable(isImmutable);
621 // Process selection by feature
622 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
623 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
624 if (aSketchFeature) {
625 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage = std::shared_ptr
626 <ModelAPI_ObjectMovedMessage>(new ModelAPI_ObjectMovedMessage(this));
627 aMessage->setMovedObject(aFeature);
628 aMessage->setOriginalPosition(anOriginalPosition);
629 aMessage->setCurrentPosition(aCurrentPosition);
630 Events_Loop::loop()->send(aMessage);
635 // the modified state of the current operation should be updated if there are features, which
638 aCurrentOperation->onValuesChanged();
639 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
641 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
643 // 5. it is necessary to save current selection in order to restore it after the features moving
644 restoreSelection(myCurrentSelection);
645 // 6. restore the update viewer flag and call this update
646 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
647 aDisplayer->updateViewer();
650 myCurrentPoint = aMousePnt;
654 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
656 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
657 (getCurrentOperation());
658 if (aFOperation && aFOperation->isEditOperation()) {
659 std::string aId = aFOperation->id().toStdString();
660 if (isDistanceOperation(aFOperation))
662 // Activate dimension value editing on double click
663 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
664 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
665 // Find corresponded widget to activate value editing
666 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
667 std::string anId = aWgt->attributeID();
668 if (anId == SketchPlugin_Constraint::VALUE() ||
669 anId == SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID() ||
670 anId == SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()) {
671 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
673 anEditor->showPopupEditor();
681 void PartSet_SketcherMgr::onApplicationStarted()
683 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
684 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
685 XGUI_Workshop* aWorkshop = aConnector->workshop();
686 PartSet_SketcherReentrantMgr* aReentranceMgr = myModule->sketchReentranceMgr();
688 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
689 if (aPropertyPanel) {
690 //connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
691 // this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
693 connect(aPropertyPanel, SIGNAL(noMoreWidgets(const std::string&)),
694 aReentranceMgr, SLOT(onNoMoreWidgets(const std::string&)));
695 //connect(aPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
696 // aReentranceMgr, SLOT(onWidgetActivated()));
699 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
700 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
701 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
703 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
704 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
705 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
708 //void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
710 //if (!myClickedPoint.myIsInitialized)
713 //ModuleBase_Operation* aOperation = getCurrentOperation();
714 // the distance constraint feature should not use the clickedd point
715 // this is workaround in order to don't throw down the flyout point value,
716 // set by execute() method of these type of features
717 //if (isDistanceOperation(aOperation))
720 //PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
722 // aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
726 void PartSet_SketcherMgr::onBeforeContextMenu()
728 myIsPopupMenuActive = true;
731 void PartSet_SketcherMgr::onAfterContextMenu()
733 myIsPopupMenuActive = false;
736 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
739 Handle(V3d_View) aView = theWnd->v3dView();
740 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
742 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
743 thePoint.setValue(aX, anY);
746 void PartSet_SketcherMgr::launchEditing()
748 if (!myCurrentSelection.empty()) {
749 FeaturePtr aFeature = myCurrentSelection.begin().key();
750 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
751 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
753 if (!aSPFeature->isExternal())
754 myModule->editFeature(aSPFeature);
756 // need to edit a feature (Projection/IntersectionPoint),
757 // which produces current External feature
758 FeaturePtr aProducerFeature = PartSet_Tools::findRefsToMeFeature(aFeature,
759 SketchPlugin_Projection::ID());
760 if (!aProducerFeature.get())
761 aProducerFeature = PartSet_Tools::findRefsToMeFeature(aFeature,
762 SketchPlugin_IntersectionPoint::ID());
763 if (aProducerFeature.get())
764 myModule->editFeature(aProducerFeature);
770 bool PartSet_SketcherMgr::sketchSolverError()
772 bool anError = false;
773 CompositeFeaturePtr aSketch = activeSketch();
775 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
776 anError = !aAttributeString->value().empty();
781 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
784 if (!theFeature.get() || !theFeature->data()->isValid())
787 CompositeFeaturePtr aSketch = activeSketch();
788 if (aSketch.get() && aSketch == theFeature) {
789 std::string aSolverError = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR())->value();
790 anError = ModuleBase_Tools::translate(aSketch->getKind(), aSolverError);
795 void PartSet_SketcherMgr::clearClickedFlags()
797 //myClickedPoint.clear();
798 myCurrentPoint.clear();
801 const QStringList& PartSet_SketcherMgr::replicationsIdList()
803 static QStringList aReplicationIds;
804 if (aReplicationIds.size() == 0) {
805 aReplicationIds << SketchPlugin_ConstraintMirror::ID().c_str();
806 aReplicationIds << SketchPlugin_MultiRotation::ID().c_str();
807 aReplicationIds << SketchPlugin_MultiTranslation::ID().c_str();
809 return aReplicationIds;
812 const QStringList& PartSet_SketcherMgr::constraintsIdList()
814 static QStringList aConstraintIds;
815 if (aConstraintIds.size() == 0) {
816 aConstraintIds << SketchPlugin_ConstraintLength::ID().c_str();
817 aConstraintIds << SketchPlugin_ConstraintDistance::ID().c_str();
818 aConstraintIds << SketchPlugin_ConstraintRigid::ID().c_str();
819 aConstraintIds << SketchPlugin_ConstraintRadius::ID().c_str();
820 aConstraintIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
821 aConstraintIds << SketchPlugin_ConstraintParallel::ID().c_str();
822 aConstraintIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
823 aConstraintIds << SketchPlugin_ConstraintVertical::ID().c_str();
824 aConstraintIds << SketchPlugin_ConstraintEqual::ID().c_str();
825 aConstraintIds << SketchPlugin_ConstraintTangent::ID().c_str();
826 aConstraintIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
827 aConstraintIds << SketchPlugin_ConstraintAngle::ID().c_str();
828 aConstraintIds << SketchPlugin_ConstraintCollinear::ID().c_str();
829 aConstraintIds << SketchPlugin_ConstraintMiddle::ID().c_str();
830 aConstraintIds << SketchPlugin_ConstraintMirror::ID().c_str();
831 aConstraintIds << SketchPlugin_MultiTranslation::ID().c_str();
832 aConstraintIds << SketchPlugin_MultiRotation::ID().c_str();
833 aConstraintIds << SketchPlugin_ConstraintDistanceAlongDir::ID().c_str();
834 aConstraintIds << SketchPlugin_ConstraintDistanceHorizontal::ID().c_str();
835 aConstraintIds << SketchPlugin_ConstraintDistanceVertical::ID().c_str();
837 return aConstraintIds;
840 void PartSet_SketcherMgr::sketchSelectionModes(const CompositeFeaturePtr& theSketch,
843 if (!theSketch.get() || !PartSet_Tools::sketchPlane(theSketch).get())
846 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
847 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
848 theModes.append(SketcherPrs_Tools::Sel_Constraint);
849 theModes.append(TopAbs_VERTEX);
850 theModes.append(TopAbs_EDGE);
853 Handle(AIS_InteractiveObject) PartSet_SketcherMgr::createPresentation(const ResultPtr& theResult)
855 Handle(AIS_InteractiveObject) aPrs;
857 FeaturePtr aFeature = ModelAPI_Feature::feature(theResult);
858 if (aFeature.get() && aFeature->getKind() == SketchPlugin_Sketch::ID()) {
859 aPrs = new PartSet_ResultSketchPrs(theResult);
864 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
866 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
869 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation) const
871 bool aNestedSketch = false;
873 FeaturePtr anActiveSketch = activeSketch();
874 if (anActiveSketch.get() && theOperation) {
875 ModuleBase_Operation* aSketchOperation = operationMgr()->findOperation(
876 anActiveSketch->getKind().c_str());
877 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
879 if (aSketchOperation && aFOperation) {
880 FeaturePtr aFeature = aFOperation->feature();
881 if (aFeature.get()) {
882 QStringList aGrantedOpIds = aSketchOperation->grantedOperationIds();
883 aNestedSketch = aGrantedOpIds.contains(aFeature->getKind().c_str());
887 return aNestedSketch;
890 bool PartSet_SketcherMgr::isNestedSketchFeature(const QString& theFeatureKind) const
892 bool aNestedSketch = false;
894 FeaturePtr anActiveSketch = activeSketch();
895 if (anActiveSketch.get()) {
896 ModuleBase_Operation* aSketchOperation = operationMgr()->findOperation(
897 anActiveSketch->getKind().c_str());
898 if (aSketchOperation) {
899 QStringList aGrantedOpIds = aSketchOperation->grantedOperationIds();
900 aNestedSketch = aGrantedOpIds.contains(theFeatureKind);
903 return aNestedSketch;
906 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation,
907 const CompositeFeaturePtr& theSketch) const
909 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
911 return aFOperation && !aFOperation->isEditOperation() &&
912 isNestedSketchOperation(aFOperation);
915 bool PartSet_SketcherMgr::isNestedEditOperation(ModuleBase_Operation* theOperation,
916 const CompositeFeaturePtr& theSketch) const
918 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
920 return aFOperation && aFOperation->isEditOperation() &&
921 isNestedSketchOperation(aFOperation);
924 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
926 return (theId == SketchPlugin_Line::ID()) ||
927 (theId == SketchPlugin_Point::ID()) ||
928 (theId == SketchPlugin_Arc::ID()) ||
929 (theId == SketchPlugin_Circle::ID());
932 bool PartSet_SketcherMgr::isExternalFeature(const FeaturePtr& theFeature)
934 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
935 std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
936 return aSPFeature.get() && aSPFeature->isExternal();
939 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
941 std::string anId = theOperation ? theOperation->id().toStdString() : "";
943 return isDistanceKind(anId);
946 bool PartSet_SketcherMgr::isDistanceKind(std::string& theKind)
948 return (theKind == SketchPlugin_ConstraintLength::ID()) ||
949 (theKind == SketchPlugin_ConstraintDistance::ID()) ||
950 (theKind == SketchPlugin_ConstraintRadius::ID()) ||
951 (theKind == SketchPlugin_ConstraintAngle::ID()) ||
952 (theKind == SketchPlugin_ConstraintDistanceHorizontal::ID()) ||
953 (theKind == SketchPlugin_ConstraintDistanceVertical::ID()) ||
954 (theKind == SketchPlugin_ConstraintDistanceAlongDir::ID());
957 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
959 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
960 (getCurrentOperation());
964 myModule->onViewTransformed();
966 // Display all sketcher sub-Objects
967 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
968 double aSizeOfView = 0;
969 std::shared_ptr<GeomAPI_Pnt> aCentralPoint;
970 if (aFOperation->isEditOperation() &&
971 mySketchPlane->getDefaultSizeOfView(myCurrentSketch, aSizeOfView, aCentralPoint)) {
972 mySketchPlane->setSizeOfView(aSizeOfView, true, aCentralPoint);
975 mySketchPlane->createSketchPlane(myCurrentSketch, myModule->workshop());
976 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
978 // Hide sketcher result
979 std::list<ResultPtr> aResults = myCurrentSketch->results();
980 std::list<ResultPtr>::const_iterator aIt;
981 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
982 (*aIt)->setDisplayed(false);
984 myCurrentSketch->setDisplayed(false);
986 // Remove invalid sketch entities
987 std::set<FeaturePtr> anInvalidFeatures;
988 ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
989 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
990 for (int i = 0; i < aNumberOfSubs; i++) {
991 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
992 if (aFeature.get()) {
993 if (!aFactory->validate(aFeature))
994 anInvalidFeatures.insert(aFeature);
997 if (!anInvalidFeatures.empty()) {
998 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
999 ModelAPI_Tools::findAllReferences(anInvalidFeatures, aReferences, false);
1001 std::set<FeaturePtr>::const_iterator anIt = anInvalidFeatures.begin(),
1002 aLast = anInvalidFeatures.end();
1003 // separate features to references to parameter features and references to others
1004 QStringList anInvalidFeatureNames;
1005 for (; anIt != aLast; anIt++) {
1006 FeaturePtr aFeature = *anIt;
1008 anInvalidFeatureNames.append(aFeature->name().c_str());
1010 std::string aPrefixInfo = QString("Invalid features of the sketch will be deleted: %1.\n\n").
1011 arg(anInvalidFeatureNames.join(", ")).toStdString().c_str();
1012 std::set<FeaturePtr> aFeatureRefsToDelete;
1013 if (ModuleBase_Tools::askToDelete(anInvalidFeatures, aReferences, aConnector->desktop(),
1014 aFeatureRefsToDelete, aPrefixInfo)) {
1015 if (!aFeatureRefsToDelete.empty())
1016 anInvalidFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1017 ModelAPI_Tools::removeFeatures(anInvalidFeatures, true);
1018 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
1019 // TODO: call the next method in the XGUI_OperationMgr::onOperationStarted().
1020 workshop()->errorMgr()->updateAcceptAllAction(myCurrentSketch);
1024 // update state of overconstraint listener should be done before sketch features/results
1025 // display (as the display will ask custom color from the listener)
1026 myModule->overconstraintListener()->setActive(true);
1027 // Display sketcher objects
1029 Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1030 const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
1031 aNumberOfSubs = myCurrentSketch->numberOfSubs();
1032 for (int i = 0; i < aNumberOfSubs; i++) {
1033 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1034 #ifdef DEBUG_SKETCHER_ENTITIES
1035 anInfo.append(ModuleBase_Tools::objectInfo(aFeature));
1037 std::list<ResultPtr> aResults = aFeature->results();
1038 std::list<ResultPtr>::const_iterator aIt;
1039 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1040 if ((*aIt)->isDisplayed())
1041 // Display object if it was created outside of GUI
1042 aECreator->sendUpdated((*aIt), EVENT_DISP);
1044 (*aIt)->setDisplayed(true);
1046 if (aFeature->isDisplayed())
1047 aECreator->sendUpdated(aFeature, EVENT_DISP);
1049 aFeature->setDisplayed(true);
1051 #ifdef DEBUG_SKETCHER_ENTITIES
1052 QString anInfoStr = anInfo.join(";\t");
1053 qDebug(QString("startSketch: %1, %2").arg(anInfo.size()).arg(anInfoStr).toStdString().c_str());
1056 bool aHasPlane = false;
1057 std::shared_ptr<GeomAPI_Pln> aPln;
1058 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
1059 Handle(SelectMgr_Filter) aFilter = myModule->selectionFilter(SF_SketchPlaneFilter);
1060 if (!aFilter.IsNull())
1061 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(aPln);
1063 workshop()->selectionActivate()->updateSelectionFilters();
1064 workshop()->selectionActivate()->updateSelectionModes();
1066 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1068 myExternalPointsMgr = new PartSet_ExternalPointsMgr(myModule->workshop(), myCurrentSketch);
1070 workshop()->viewer()->set2dMode(true);
1073 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
1075 myIsMouseOverWindow = false;
1076 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
1077 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
1078 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
1080 if (myExternalPointsMgr) {
1081 delete myExternalPointsMgr;
1082 myExternalPointsMgr = 0;
1084 onShowPoints(false);
1086 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
1088 DataPtr aData = myCurrentSketch->data();
1089 if (!aData->isValid()) {
1090 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1091 // The sketch was aborted
1092 myCurrentSketch = CompositeFeaturePtr();
1093 mySketchPlane->eraseSketchPlane(myModule->workshop());
1095 // Erase all sketcher objects
1096 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1097 foreach (ObjectPtr aObj, aObjects) {
1098 DataPtr aObjData = aObj->data();
1099 if (!aObjData->isValid())
1100 aObj->setDisplayed(false);
1104 // Hide all sketcher sub-Objects
1105 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
1106 for (int i = 0; i < aNumberOfSubs; i++) {
1107 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1108 std::list<ResultPtr> aResults = aFeature->results();
1109 std::list<ResultPtr>::const_iterator aIt;
1110 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1111 (*aIt)->setDisplayed(false);
1113 aFeature->setDisplayed(false);
1115 // Display sketcher result
1116 std::list<ResultPtr> aResults = myCurrentSketch->results();
1117 std::list<ResultPtr>::const_iterator aIt;
1118 Events_Loop* aLoop = Events_Loop::loop();
1119 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1121 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1123 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1124 if (!aFOperation->isDisplayedOnStart(*aIt)) {
1125 (*aIt)->setDisplayed(true);
1126 // this display event is needed because sketch already may have "displayed" state,
1127 // but not displayed while it is still active (issue 613, abort of existing sketch)
1128 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
1131 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
1132 myCurrentSketch->setDisplayed(true);
1134 myCurrentSketch = CompositeFeaturePtr();
1135 mySketchPlane->eraseSketchPlane(myModule->workshop());
1137 Events_Loop::loop()->flush(aDispEvent);
1139 workshop()->selectionActivate()->updateSelectionFilters();
1140 workshop()->selectionActivate()->updateSelectionModes();
1141 workshop()->viewer()->set2dMode(false);
1144 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
1146 if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
1147 QCursor* aCurrentCursor = QApplication::overrideCursor();
1148 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
1149 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
1151 qDebug("startNestedSketch() : Qt::CrossCursor");
1157 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
1159 myIsMouseOverViewProcessed = true;
1160 operationMgr()->onValidateOperation();
1161 // when sketch nested operation is stopped the cursor should be restored unconditionally
1162 //if (canChangeCursor(theOperation)) {
1163 QApplication::restoreOverrideCursor();
1165 qDebug("stopNestedSketch() : None");
1168 /// improvement to deselect automatically all eventual selected objects, when
1169 // returning to the neutral point of the Sketcher
1170 bool isClearSelectionPossible = true;
1171 if (myIsEditLaunching) {
1172 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1175 FeaturePtr aFeature = aFOperation->feature();
1176 if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
1177 isClearSelectionPossible = false;
1181 if (isClearSelectionPossible)
1182 workshop()->selector()->clearSelection();
1183 if (myPointsHighlight.size())
1187 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
1189 if (isNestedCreateOperation(theOperation, activeSketch())) {
1190 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1193 FeaturePtr aFeature = aFOperation->feature();
1194 // it is necessary to check the the feature data validity because
1195 // some kind of features are removed by an operation commit(the macro state of a feature)
1196 if (aFeature.get() && aFeature->data()->isValid()) {
1197 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
1203 bool PartSet_SketcherMgr::sketchSelectionFilter(const ModuleBase_SelectionFilterType theFilterType)
1205 return mySelectionFilterTypes.find(theFilterType) != mySelectionFilterTypes.end();
1208 void PartSet_SketcherMgr::registerSelectionFilter(
1209 const ModuleBase_SelectionFilterType theFilterType, const Handle(SelectMgr_Filter)& theFilter)
1211 mySelectionFilterTypes.insert(theFilterType);
1212 myModule->registerSelectionFilter(theFilterType, theFilter);
1215 bool PartSet_SketcherMgr::operationActivatedByPreselection()
1217 bool isOperationStopped = false;
1218 ModuleBase_Operation* anOperation = getCurrentOperation();
1219 if(anOperation && isNestedSketchOperation(anOperation)) {
1220 // Set final definitions if they are necessary
1221 //propertyPanelDefined(aOperation);
1222 /// Commit sketcher operations automatically
1223 /// distance operation are able to show popup editor to modify the distance value
1224 /// after entering the value, the operation should be committed/aborted(by Esc key)
1225 bool aCanCommitOperation = true;
1226 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1228 if (aFOperation && PartSet_SketcherMgr::isDistanceOperation(aFOperation)) {
1229 bool aValueAccepted = setDistanceValueByPreselection(anOperation, myModule->workshop(),
1230 aCanCommitOperation);
1231 if (!aValueAccepted)
1232 return isOperationStopped;
1235 if (aCanCommitOperation)
1236 isOperationStopped = anOperation->commit();
1238 anOperation->abort();
1239 isOperationStopped = true;
1242 return isOperationStopped;
1245 bool PartSet_SketcherMgr::canUndo() const
1247 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1250 bool PartSet_SketcherMgr::canRedo() const
1252 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1255 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1257 bool aCanErase = true;
1258 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1259 if (myCurrentSketch.get()) {
1260 return !isObjectOfSketch(theObject);
1265 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1267 bool aCanDisplay = true;
1269 bool aHasActiveSketch = activeSketch().get() != NULL;
1270 if (aHasActiveSketch) {
1271 // 1. the sketch feature should not be displayed during the sketch active operation
1272 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1273 // nested features can be visualized
1274 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1275 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1276 aCanDisplay = false;
1278 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1279 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1280 /// some sketch entities should be never shown, e.g. projection feature
1281 if (aSketchFeature.get())
1282 aCanDisplay = aSketchFeature->canBeDisplayed();
1284 else { // there are no an active sketch
1285 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1286 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1287 if (aFeature.get() != NULL) {
1288 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1289 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1290 if (aSketchFeature.get()) {
1291 aCanDisplay = false;
1296 // 3. the method should not filter the objects, which are not related to the current operation.
1297 // The object is filtered just if it is a current operation feature or this feature result
1299 bool isObjectFound = false;
1300 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1301 (getCurrentOperation());
1303 FeaturePtr aFeature = aFOperation->feature();
1304 if (aFeature.get()) {
1305 std::list<ResultPtr> aResults = aFeature->results();
1306 if (theObject == aFeature)
1307 isObjectFound = true;
1309 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1310 for (; anIt != aLast && !isObjectFound; anIt++) {
1311 isObjectFound = *anIt == theObject;
1316 if (isObjectFound) {
1317 // 4. For created nested feature operation do not display the created feature if
1318 // the mouse curstor leaves the OCC window.
1319 // The correction cases, which ignores this condition:
1320 // a. the property panel values modification
1321 // b. the popup menu activated
1322 // c. widget editor control
1323 #ifndef DEBUG_DO_NOT_BY_ENTER
1324 if (isNestedCreateOperation(getCurrentOperation(), activeSketch())) {
1325 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1326 ModuleBase_WidgetEditor* anEditorWdg =
1327 anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1328 // the active widget editor should not influence here. The presentation should be visible
1329 // always when this widget is active.
1330 if (!anEditorWdg && !myIsPopupMenuActive) {
1331 // during a nested create operation, the feature is redisplayed only
1332 // if the mouse over view
1333 // of there was a value modified in the property panel after the mouse left the view
1334 aCanDisplay = canDisplayCurrentCreatedFeature();
1341 // checks the sketcher constraints visibility according to active sketch check box states
1343 bool aProcessed = false;
1344 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1345 if (aFeature.get()) {
1346 bool aConstraintDisplayed = canDisplayConstraint(aFeature, PartSet_Tools::Any, aProcessed);
1348 aCanDisplay = aConstraintDisplayed;
1355 bool PartSet_SketcherMgr::canDisplayConstraint(const FeaturePtr& theFeature,
1356 const PartSet_Tools::ConstraintVisibleState& theState,
1357 bool& isProcessed) const
1359 bool aSwitchedOn = true;
1361 const QStringList& aConstrIds = constraintsIdList();
1363 std::string aKind = theFeature->getKind();
1364 if (aConstrIds.contains(QString(aKind.c_str()))) {
1365 bool isTypedConstraint = false;
1368 case PartSet_Tools::Dimensional: {
1369 bool isDistance = isDistanceKind(aKind);
1372 aSwitchedOn = myIsConstraintsShown[theState];
1376 case PartSet_Tools::Geometrical: {
1377 bool isGeometrical = !isDistanceKind(aKind);
1378 if (isGeometrical) {
1380 aSwitchedOn = myIsConstraintsShown[theState];
1384 case PartSet_Tools::Any: {
1386 bool isDistance = isDistanceKind(aKind);
1388 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Dimensional];
1390 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Geometrical];
1400 /*void PartSet_SketcherMgr::processHiddenObject(const std::list<ObjectPtr>& theObjects)
1402 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1403 (getCurrentOperation());
1404 if (aFOperation && myCurrentSketch.get()) {
1405 // find results of the current operation
1406 // these results should not be proposed to be deleted
1407 FeaturePtr anOperationFeature = aFOperation->feature();
1408 std::list<ResultPtr> anOperationResultList = anOperationFeature->results();
1409 std::set<ResultPtr> anOperationResults;
1410 std::list<ResultPtr>::const_iterator aRIt = anOperationResultList.begin(),
1411 aRLast = anOperationResultList.end();
1412 for (; aRIt != aRLast; aRIt++)
1413 anOperationResults.insert(*aRIt);
1415 std::set<FeaturePtr> anObjectsToBeDeleted;
1416 QStringList anObjectsToBeDeletedNames;
1417 std::list<ObjectPtr>::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1418 for (; anIt != aLast; anIt++) {
1419 ObjectPtr anObject = *anIt;
1420 bool aCanErase = true;
1421 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1422 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1423 // the result is found between current feature results
1424 if (anOperationResults.find(aResult) != anOperationResults.end())
1427 if (aResult.get()) {
1428 // Display sketcher objects
1429 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1430 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1431 std::list<ResultPtr> aResults = aFeature->results();
1432 std::list<ResultPtr>::const_iterator anIt;
1433 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1434 aCanErase = *anIt != aResult;
1439 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1440 if (aFeature.get() && anObjectsToBeDeleted.find(aFeature) == anObjectsToBeDeleted.end()) {
1441 anObjectsToBeDeleted.insert(aFeature);
1442 anObjectsToBeDeletedNames.append(aFeature->name().c_str());
1446 if (!anObjectsToBeDeleted.empty()) {
1447 QString aFeatureNames = anObjectsToBeDeletedNames.join(", ");
1448 QString aMessage = tr("The following features have incorrect presentation and \
1449 will be hidden: %1. Would you like to delete them?")
1450 .arg(aFeatureNames);
1451 int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Features hide"),
1452 aMessage, QMessageBox::Ok | QMessageBox::Cancel,
1453 QMessageBox::Cancel);
1454 if (anAnswer == QMessageBox::Ok) {
1455 QObjectPtrList anObjects;
1456 std::set<FeaturePtr>::const_iterator anIt = anObjectsToBeDeleted.begin(),
1457 aLast = anObjectsToBeDeleted.end();
1458 for (; anIt != aLast; anIt++)
1459 anObjects.append(*anIt);
1460 SessionPtr aMgr = ModelAPI_Session::get();
1461 DocumentPtr aDoc = aMgr->activeDocument();
1462 bool aIsOp = aMgr->isOperation();
1464 aMgr->startOperation();
1465 workshop()->deleteFeatures(anObjects);
1466 //static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
1467 //static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
1468 //Events_Loop::loop()->flush(aDeletedEvent);
1469 //Events_Loop::loop()->flush(aRedispEvent);
1472 aMgr->finishOperation();
1478 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1480 bool aCanDisplay = myIsMouseOverWindow;
1482 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1484 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1489 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1491 return isNestedCreateOperation(theOperation, activeSketch()) ||
1492 myModule->sketchReentranceMgr()->isInternalEditActive();
1495 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
1497 return myIsConstraintsShown;
1500 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1502 bool isFoundObject = false;
1504 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1505 if (anObjectFeature.get()) {
1506 int aSize = myCurrentSketch->numberOfSubs();
1507 for (int i = 0; i < aSize && !isFoundObject; i++) {
1508 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1509 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1512 return isFoundObject;
1515 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePlane)
1517 Handle(SelectMgr_Filter) aFilter = myModule->selectionFilter(SF_SketchPlaneFilter);
1518 if (!aFilter.IsNull())
1519 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(thePlane);
1521 workshop()->selectionActivate()->updateSelectionModes();
1524 bool PartSet_SketcherMgr::setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
1525 ModuleBase_IWorkshop* theWorkshop,
1526 bool& theCanCommitOperation)
1528 bool isValueAccepted = false;
1529 theCanCommitOperation = false;
1531 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1533 FeaturePtr aFeature = aFOperation->feature();
1534 // editor is shown only if all attribute references are filled by preseletion
1535 bool anAllRefAttrInitialized = true;
1537 std::list<AttributePtr> aRefAttrs = aFeature->data()->attributes(
1538 ModelAPI_AttributeRefAttr::typeId());
1539 std::list<AttributePtr>::const_iterator anIt = aRefAttrs.begin(), aLast = aRefAttrs.end();
1540 for (; anIt != aLast && anAllRefAttrInitialized; anIt++) {
1541 anAllRefAttrInitialized = (*anIt)->isInitialized();
1543 if (anAllRefAttrInitialized) {
1544 // Activate dimension value editing on double click
1545 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
1546 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
1547 // Find corresponded widget to activate value editing
1548 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
1549 if (aWgt->attributeID() == "ConstraintValue") {
1550 // the featue should be displayed in order to find the AIS text position,
1551 // the place where the editor will be shown
1552 aFeature->setDisplayed(true);
1553 /// the execute is necessary to perform in the feature compute for flyout position
1554 aFeature->execute();
1556 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1557 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1559 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
1561 int aX = 0, anY = 0;
1563 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(theWorkshop);
1564 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1565 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
1566 Handle(AIS_InteractiveObject) anAISIO;
1567 if (anAIS.get() != NULL) {
1568 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1570 if (anAIS.get() != NULL) {
1571 Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1573 if (!anAISIO.IsNull()) {
1574 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
1575 if (!aDim.IsNull()) {
1576 gp_Pnt aPosition = aDim->GetTextPosition();
1578 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
1579 Handle(V3d_View) aView = aViewer->activeView();
1581 aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
1583 QWidget* aViewPort = aViewer->activeViewPort();
1584 QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
1589 anEditor->setCursorPosition(aX, anY);
1590 isValueAccepted = anEditor->showPopupEditor(false);
1591 theCanCommitOperation = true;
1597 return isValueAccepted;
1600 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1601 const FeaturePtr& theSketch,
1602 ModuleBase_IWorkshop* theWorkshop,
1603 const FeatureToSelectionMap& theSelection,
1604 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1606 if (theFeature.get() == NULL)
1609 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1610 SelectionInfo anInfo = anIt.value();
1611 std::set<AttributePtr> aSelectedAttributes = anInfo.myAttributes;
1612 std::set<ResultPtr> aSelectedResults = anInfo.myResults;
1614 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1616 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1617 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1619 // 1. found the feature's owners. Check the AIS objects of the constructions
1620 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1621 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1622 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1624 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1625 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1626 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1627 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1628 if (!anOwner.IsNull())
1629 theOwnersToSelect.Add(anOwner);
1633 // 2. found the feature results's owners
1634 std::list<ResultPtr> aResults = theFeature->results();
1635 std::list<ResultPtr>::const_iterator aIt;
1637 bool isSameShape = false;
1638 if (aResults.size() > 0) {
1639 ResultPtr aFirstResult = theFeature->firstResult();
1640 if (aFirstResult.get() && aFirstResult->shape().get()) {
1641 TopoDS_Shape aFirstShape = aFirstResult->shape()->impl<TopoDS_Shape>();
1642 isSameShape = aFirstShape.IsEqual(anInfo.myFirstResultShape);
1645 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1646 ResultPtr aResult = *aIt;
1647 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1648 if (aAISObj.get() == NULL)
1650 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1652 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1653 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1654 bool aFoundLocalShape = false;
1655 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1656 Handle(StdSelect_BRepOwner) anOwner =
1657 Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1658 if ( anOwner.IsNull() || !anOwner->HasShape() || theOwnersToSelect.FindIndex(anOwner))
1660 const TopoDS_Shape& aShape = anOwner->Shape();
1661 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1662 if (aShapeType == TopAbs_VERTEX) {
1663 AttributePtr aPntAttr =
1664 PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1665 if (aPntAttr.get() != NULL &&
1666 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end())
1667 theOwnersToSelect.Add(anOwner);
1668 else if (isSameShape && anInfo.myLocalSelectedShapes.Contains(aShape)) {
1669 theOwnersToSelect.Add(anOwner);
1672 else if (aShapeType == TopAbs_EDGE) {
1673 if (isSameShape && anInfo.myLocalSelectedShapes.Contains(aShape)) {
1674 // try to restore local selection on Shape result
1675 // we can do this only if the shape was not changed
1676 theOwnersToSelect.Add(anOwner);
1677 aFoundLocalShape = true;
1682 if (!aFoundLocalShape) {
1683 // result owners are put in the list of selection only if local selected shapes were not
1685 if (aSelectedResults.find(aResult) != aSelectedResults.end()) {
1686 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1687 Handle(StdSelect_BRepOwner) anOwner =
1688 Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1689 if ( anOwner.IsNull() || !anOwner->HasShape() || theOwnersToSelect.FindIndex(anOwner))
1691 // select whole result
1692 theOwnersToSelect.Add(anOwner);
1699 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
1700 const bool isToConnect)
1702 //Temporary commented as we do not modify values in property panel
1704 //connect(theWidget, SIGNAL(beforeValuesChanged()),
1705 // this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1706 //connect(theWidget, SIGNAL(afterValuesChanged()),
1707 // this, SLOT(onAfterValuesChangedInPropertyPanel()));
1708 connect(theWidget, SIGNAL(afterValuesChanged()),
1709 myModule->sketchReentranceMgr(), SLOT(onAfterValuesChangedInPropertyPanel()));
1712 //disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1713 // this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1714 //disconnect(theWidget, SIGNAL(afterValuesChanged()),
1715 // this, SLOT(onAfterValuesChangedInPropertyPanel()));
1716 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1717 myModule->sketchReentranceMgr(), SLOT(onAfterValuesChangedInPropertyPanel()));
1721 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1723 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1724 (getCurrentOperation());
1726 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1727 isNestedSketchOperation(aFOperation) &&
1728 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1729 FeaturePtr aFeature = aFOperation->feature();
1730 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1735 void PartSet_SketcherMgr::customizePresentation(const ObjectPtr& theObject)
1737 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1738 (getCurrentOperation());
1739 if (aFOperation && (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1740 isNestedSketchOperation(aFOperation)))
1741 SketcherPrs_Tools::sendExpressionShownEvent(myIsConstraintsShown[PartSet_Tools::Expressions]);
1743 // update entities selection priorities
1744 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1745 if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
1746 // update priority for feature
1747 updateSelectionPriority(aFeature, aFeature);
1748 // update priority for results of the feature
1749 std::list<ResultPtr> aResults = aFeature->results();
1750 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLastIt = aResults.end();
1751 for (; anIt != aLastIt; anIt++)
1752 updateSelectionPriority(*anIt, aFeature);
1756 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1758 return myModule->workshop()->currentOperation();
1761 //**************************************************************
1762 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1764 ModuleBase_ModelWidget* aWidget = 0;
1765 ModuleBase_Operation* anOperation = getCurrentOperation();
1767 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1769 aWidget = aPanel->activeWidget();
1774 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1775 const bool isEditOperation,
1776 const bool isToDisplay,
1777 const bool isFlushRedisplay)
1779 #ifdef DEBUG_DO_NOT_BY_ENTER
1783 if (isEditOperation || !theFeature.get())
1786 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1787 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1789 // 1. change visibility of the object itself, here the presentable object is processed,
1790 // e.g. constraints features
1791 //FeaturePtr aFeature = aFOperation->feature();
1792 std::list<ResultPtr> aResults = theFeature->results();
1794 theFeature->setDisplayed(true);
1796 theFeature->setDisplayed(false);
1798 // change visibility of the object results, e.g. non-constraint features
1799 std::list<ResultPtr>::const_iterator aIt;
1800 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1802 (*aIt)->setDisplayed(true);
1805 (*aIt)->setDisplayed(false);
1808 if (isFlushRedisplay)
1809 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1812 void PartSet_SketcherMgr::storeSelection(const SelectionType theType,
1813 PartSet_SketcherMgr::FeatureToSelectionMap& theCurrentSelection)
1815 if (!myCurrentSketch.get())
1818 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1819 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1820 QList<ModuleBase_ViewerPrsPtr> aStoredPrs;
1822 if (theType == ST_HighlightType || theType == ST_SelectAndHighlightType)
1823 aStoredPrs = aSelect->getHighlighted();
1825 QList<FeaturePtr> aFeatureList;
1826 if (theType == ST_SelectAndHighlightType || theType == ST_SelectType) {
1827 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected(
1828 ModuleBase_ISelection::AllControls);
1829 aStoredPrs.append(aSelected);
1832 // 1. it is necessary to save current selection in order to restore it after the features moving
1833 theCurrentSelection.clear();
1835 QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = aStoredPrs.begin(),
1836 aLast = aStoredPrs.end();
1838 CompositeFeaturePtr aSketch = activeSketch();
1839 for (; anIt != aLast; anIt++) {
1840 ModuleBase_ViewerPrsPtr aPrs = *anIt;
1841 ObjectPtr anObject = aPrs->object();
1842 if (!anObject.get())
1845 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1846 FeaturePtr aFeature;
1848 aFeature = ModelAPI_Feature::feature(aResult);
1850 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1852 if (!aFeature.get())
1855 std::set<AttributePtr> aSelectedAttributes;
1856 std::set<ResultPtr> aSelectedResults;
1857 SelectionInfo anInfo;
1858 if (theCurrentSelection.find(aFeature) != theCurrentSelection.end())
1859 anInfo = theCurrentSelection.find(aFeature).value();
1861 TopoDS_Shape aFirstShape;
1862 ResultPtr aFirstResult = aFeature->firstResult();
1863 if (aFirstResult.get() && aFirstResult->shape().get())
1864 aFirstShape = aFirstResult->shape()->impl<TopoDS_Shape>();
1865 anInfo.myFirstResultShape = aFirstShape;
1866 Handle(SelectMgr_EntityOwner) anOwner = aPrs->owner();
1867 if (aResult.get()) {
1868 getAttributesOrResults(anOwner, aFeature, aSketch, aResult,
1869 anInfo.myAttributes, anInfo.myResults, anInfo.myLocalSelectedShapes);
1872 std::list<ResultPtr> aResults = aFeature->results();
1873 std::list<ResultPtr>::const_iterator aIt;
1874 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1875 ResultPtr aResult = *aIt;
1876 getAttributesOrResults(anOwner, aFeature, aSketch, aResult,
1877 anInfo.myAttributes, anInfo.myResults, anInfo.myLocalSelectedShapes);
1880 theCurrentSelection[aFeature] = anInfo;
1882 //qDebug(QString(" storeSelection: %1").arg(theCurrentSelection.size()).toStdString().c_str());
1885 void PartSet_SketcherMgr::restoreSelection(
1886 PartSet_SketcherMgr::FeatureToSelectionMap& theCurrentSelection)
1888 if (!myCurrentSketch.get())
1891 //qDebug(QString("restoreSelection: %1").arg(theCurrentSelection.size()).toStdString().c_str());
1892 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1893 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1894 FeatureToSelectionMap::const_iterator aSIt = theCurrentSelection.begin(),
1895 aSLast = theCurrentSelection.end();
1896 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1897 anOwnersToSelect.Clear();
1898 for (; aSIt != aSLast; aSIt++) {
1899 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, theCurrentSelection,
1902 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1905 void PartSet_SketcherMgr::onShowConstraintsToggle(int theType, bool theState)
1907 PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
1909 updateBySketchParameters(aType, theState);
1912 void PartSet_SketcherMgr::updateBySketchParameters(
1913 const PartSet_Tools::ConstraintVisibleState& theType,
1916 if (myCurrentSketch.get() == NULL)
1919 bool aPrevState = myIsConstraintsShown[theType];
1920 myIsConstraintsShown[theType] = theState;
1923 case PartSet_Tools::Geometrical:
1924 case PartSet_Tools::Dimensional: {
1925 if (aPrevState != theState) {
1926 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1927 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1928 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
1929 for (int i = 0; i < aNumberOfSubs; i++) {
1930 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1931 bool aProcessed = false;
1932 bool aConstraintDisplayed = canDisplayConstraint(aSubFeature, theType, aProcessed);
1934 aSubFeature->setDisplayed(aConstraintDisplayed);
1936 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1940 case PartSet_Tools::Expressions: {
1941 if (aPrevState != theState) {
1942 /// call all sketch features redisplay, the expression state will be corrected in customize
1943 /// of distance presentation
1944 Events_ID anEventId = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1945 PartSet_Tools::sendSubFeaturesEvent(myCurrentSketch, anEventId);
1952 void PartSet_SketcherMgr::updateSelectionPriority(ObjectPtr theObject,
1953 FeaturePtr theFeature)
1955 if (!theObject.get() || !theFeature.get())
1958 AISObjectPtr anAIS = workshop()->displayer()->getAISObject(theObject);
1959 Handle(AIS_InteractiveObject) anAISIO;
1960 if (anAIS.get() != NULL) {
1961 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1964 if (!anAISIO.IsNull()) { // the presentation for the object is visualized
1965 int anAdditionalPriority = 0;
1967 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
1968 std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
1969 if (aSPFeature.get() != NULL) {
1971 // 2. Simple segments
1972 // 3. External objects (violet color)
1973 // 4. Auxiliary segments (dotted)
1974 // StdSelect_BRepSelectionTool::Load uses priority calculating:
1975 // Standard_Integer aPriority =
1976 // (thePriority == -1) ? GetStandardPriority (theShape, theType) : thePriority;
1977 // Priority of Vertex is 8, edge(segment) is 7.
1978 // It might be not corrected as provides the condition above.
1979 bool isExternal = aSPFeature->isExternal();
1980 bool isAuxiliary = PartSet_Tools::isAuxiliarySketchEntity(aSPFeature);
1982 if (!isExternal && !isAuxiliary)
1983 anAdditionalPriority = 30;
1986 anAdditionalPriority = 20;
1987 // auxiliary feature
1989 anAdditionalPriority = 10; /// auxiliary objects should have less priority that
1990 // edges/vertices of local selection on not-sketch objects
1992 Handle(ModuleBase_ResultPrs) aResult = Handle(ModuleBase_ResultPrs)::DownCast(anAISIO);
1993 if (!aResult.IsNull()) {
1994 aResult->setAdditionalSelectionPriority(anAdditionalPriority);
2000 XGUI_Workshop* PartSet_SketcherMgr::workshop() const
2002 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
2003 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
2004 return aConnector->workshop();
2007 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
2009 return workshop()->operationMgr();
2012 void PartSet_SketcherMgr::onShowPoints(bool toShow)
2014 if (!myCurrentSketch.get())
2016 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
2017 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
2018 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
2020 bool aToUpdate = false;
2022 std::list<ResultPtr> aFreePoints = SketcherPrs_Tools::getFreePoints(myCurrentSketch);
2024 // Delete obsolete presentations
2025 std::list<ResultPtr> aDelList;
2026 foreach(ResultPtr aObj, myPointsHighlight.keys()) {
2027 bool aFound = (std::find(aFreePoints.begin(), aFreePoints.end(), aObj) != aFreePoints.end());
2029 aDelList.push_back(aObj);
2031 foreach(ResultPtr aObj, aDelList) {
2032 aContext->Remove(myPointsHighlight[aObj], false);
2034 myPointsHighlight.remove(aObj);
2037 // Display new objects
2038 QList<ResultPtr> aKeysList = myPointsHighlight.keys();
2039 std::list<ResultPtr>::const_iterator aIt;
2040 for (aIt = aFreePoints.cbegin(); aIt != aFreePoints.cend(); aIt++) {
2041 if (!aKeysList.contains(*aIt)) {
2042 GeomShapePtr aShapePtr = (*aIt)->shape();
2043 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
2044 Handle(AIS_Shape) aShapePrs = new AIS_Shape(aShape);
2045 aShapePrs->SetColor(Quantity_NOC_BLUE1);
2046 aShapePrs->SetZLayer(Graphic3d_ZLayerId_Top);
2047 Handle(Prs3d_Drawer) aDrawer = aShapePrs->Attributes();
2048 if (aDrawer->HasOwnPointAspect()) {
2049 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_O_STAR);
2050 aDrawer->PointAspect()->SetColor(Quantity_NOC_BLUE1);
2051 aDrawer->PointAspect()->SetScale(2);
2054 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_O_STAR, Quantity_NOC_BLUE1, 2));
2055 aContext->Display(aShapePrs, false);
2056 aContext->Deactivate(aShapePrs);
2057 myPointsHighlight[*aIt] = aShapePrs;
2063 foreach(Handle(AIS_Shape) aPrs, myPointsHighlight.values()) {
2064 aContext->Remove(aPrs, false);
2067 myPointsHighlight.clear();