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_Ellipse.h>
74 #include <SketchPlugin_EllipticArc.h>
75 #include <SketchPlugin_ConstraintLength.h>
76 #include <SketchPlugin_ConstraintDistance.h>
77 #include <SketchPlugin_ConstraintParallel.h>
78 #include <SketchPlugin_ConstraintPerpendicular.h>
79 #include <SketchPlugin_ConstraintRadius.h>
80 #include <SketchPlugin_ConstraintRigid.h>
81 #include <SketchPlugin_ConstraintHorizontal.h>
82 #include <SketchPlugin_ConstraintVertical.h>
83 #include <SketchPlugin_ConstraintEqual.h>
84 #include <SketchPlugin_ConstraintTangent.h>
85 #include <SketchPlugin_ConstraintCoincidence.h>
86 #include <SketchPlugin_Fillet.h>
87 #include <SketchPlugin_ConstraintMirror.h>
88 #include <SketchPlugin_ConstraintAngle.h>
89 #include <SketchPlugin_ConstraintCollinear.h>
90 #include <SketchPlugin_ConstraintMiddle.h>
91 #include <SketchPlugin_MultiRotation.h>
92 #include <SketchPlugin_MultiTranslation.h>
93 #include <SketchPlugin_IntersectionPoint.h>
94 #include <SketchPlugin_Projection.h>
95 #include <SketchPlugin_ConstraintDistanceAlongDir.h>
96 #include <SketchPlugin_ConstraintDistanceHorizontal.h>
97 #include <SketchPlugin_ConstraintDistanceVertical.h>
99 #include <SketcherPrs_Tools.h>
101 #include <SelectMgr_IndexedMapOfOwner.hxx>
102 #include <StdSelect_BRepOwner.hxx>
104 //#include <AIS_DimensionSelectionMode.hxx>
105 #include <AIS_Shape.hxx>
106 #include <AIS_Dimension.hxx>
108 #include <ModelAPI_Events.h>
109 #include <ModelAPI_Session.h>
110 #include <ModelAPI_AttributeString.h>
112 #include <ModelAPI_Validator.h>
113 #include <ModelAPI_Tools.h>
115 #include <QMouseEvent>
116 #include <QApplication>
118 #include <QMessageBox>
119 #include <QMainWindow>
121 //#define DEBUG_DO_NOT_BY_ENTER
122 //#define DEBUG_SKETCHER_ENTITIES
123 //#define DEBUG_SKETCH_ENTITIES_ON_MOVE
124 //#define DRAGGING_DEBUG
125 //#define DEBUG_CURSOR
128 #ifdef DRAGGING_DEBUG
132 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
133 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge,
134 /// put the function result as is to the list of results.
135 /// \param theOwner a viewer selected owner
136 /// \param theFeature a feature, where the attribute is searched
137 /// \param theSketch a current sketch
138 /// \param theSelectedAttribute an output list of attributes
139 /// \param theSelectedResults an output list of edge results
140 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
141 const FeaturePtr& theFeature, const FeaturePtr& theSketch,
142 const ResultPtr& theResult,
143 std::set<AttributePtr>& theSelectedAttributes,
144 std::set<ResultPtr>& theSelectedResults,
145 TopTools_MapOfShape& theShapes)
147 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
148 if (aBRepOwner.IsNull())
150 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
151 aBRepOwner->Selectable());
152 if (aBRepOwner->HasShape()) {
153 const TopoDS_Shape& aShape = aBRepOwner->Shape();
154 theShapes.Add(aShape);
155 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
156 if (aShapeType == TopAbs_VERTEX) {
157 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
159 if (aPntAttr.get() != NULL)
160 theSelectedAttributes.insert(aPntAttr);
162 else if (aShapeType == TopAbs_EDGE &&
163 theSelectedResults.find(theResult) == theSelectedResults.end()) {
164 theSelectedResults.insert(theResult);
169 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
170 : QObject(theModule), myModule(theModule), myIsEditLaunching(false), myIsDragging(false),
171 myDragDone(false), myIsMouseOverWindow(false),
172 myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
173 myIsPopupMenuActive(false), myExternalPointsMgr(0), myNoDragMoving(false)
175 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
176 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
178 myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
180 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
181 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
183 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
184 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
186 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
187 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
189 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
190 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
192 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
193 XGUI_Workshop* aWorkshop = aConnector->workshop();
194 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
196 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
197 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
198 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
200 mySketchPlane = new PartSet_PreviewSketchPlane();
202 registerSelectionFilter(SF_SketchCirclePointFilter, new PartSet_CirclePointFilter(anIWorkshop));
203 registerSelectionFilter(SF_SketchPlaneFilter, new ModuleBase_ShapeInPlaneFilter());
206 PartSet_SketcherMgr::~PartSet_SketcherMgr()
208 delete mySketchPlane;
211 void PartSet_SketcherMgr::onEnterViewPort()
213 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
214 // created feature because it should be done in onMouseMove(). Some widgets watch
215 // the mouse move and use the cursor position to update own values. If the presentaion is
216 // redisplayed before this update, the feature presentation jumps from reset value to current.
217 myIsMouseOverWindow = true;
219 #ifdef DEBUG_DO_NOT_BY_ENTER
223 // It is switched off because of
224 // Task #3067: 5.2.2 Drawing in the sketcher: change the mouse cursor arrow
225 // if (canChangeCursor(getCurrentOperation())) {
226 // QCursor* aCurrentCursor = QApplication::overrideCursor();
227 // if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
228 // QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
229 //#ifdef DEBUG_CURSOR
230 // qDebug("onEnterViewPort() : Qt::CrossCursor");
235 if (!isNestedCreateOperation(getCurrentOperation(), activeSketch()))
238 operationMgr()->onValidateOperation();
240 // we need change displayed state of the current operation feature
241 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
242 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
243 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
244 // presentation becomes valid and redisplay happens
245 //ModuleBase_Operation* aOperation = getCurrentOperation();
246 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
247 (getCurrentOperation());
249 FeaturePtr aFeature = aFOperation->feature();
250 if (aFeature.get() && aFeature->data()->isValid()) {
251 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
256 void PartSet_SketcherMgr::onLeaveViewPort()
258 myIsMouseOverViewProcessed = false;
259 myIsMouseOverWindow = false;
261 #ifdef DEBUG_DO_NOT_BY_ENTER
265 // if (canChangeCursor(getCurrentOperation())) {
266 // QApplication::restoreOverrideCursor();
267 //#ifdef DEBUG_CURSOR
268 // qDebug("onLeaveViewPort() : None");
272 if (!isNestedCreateOperation(getCurrentOperation(), activeSketch()))
275 // the method should be performed if the popup menu is called,
276 // the reset of the current widget should not happen
277 if (myIsPopupMenuActive)
280 // it is important to validate operation here only if sketch entity create operation is active
281 // because at this operation we reacts to the mouse leave/enter view port
282 operationMgr()->onValidateOperation();
284 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
285 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
286 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
287 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
288 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
289 // obtained after reset value
290 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
291 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
293 anActiveWidget->reset();
295 // hides the presentation of the current operation feature
296 // the feature is to be erased here, but it is correct to call canDisplayObject because
297 // there can be additional check (e.g. editor widget in distance constraint)
298 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
299 (getCurrentOperation());
301 FeaturePtr aFeature = aFOperation->feature();
302 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
304 // we should update viewer after the presentation are hidden in the viewer
305 // otherwise the reset presentation(line) appears in the viewer(by quick move from viewer to PP)
306 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
310 //Temporary commented as we do not modify values in property panel
311 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
313 if (!isNestedEditOperation(getCurrentOperation(), myModule->sketchMgr()->activeSketch()) ||
314 myModule->sketchReentranceMgr()->isInternalEditActive())
316 // it is necessary to save current selection in order to restore it after the values are modifed
317 storeSelection(ST_SelectAndHighlightType);
319 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
320 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
321 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
322 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
325 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
327 if (!isNestedEditOperation(getCurrentOperation(), myModule->sketchMgr()->activeSketch()) ||
328 myModule->sketchReentranceMgr()->isInternalEditActive()) {
329 myModule->sketchReentranceMgr()->updateInternalEditActiveState();
332 // it is necessary to restore current selection in order to restore it after values are modified
334 myCurrentSelection.clear();
336 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
337 // viewer happens by deselect/select the modified objects. The flag should be restored after
338 // the selection processing. The update viewer should be also called.
339 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
340 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
341 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
342 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
343 aDisplayer->updateViewer();
347 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
349 // Clear dragging mode
350 myIsDragging = false;
352 if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
354 //get2dPoint(theWnd, theEvent, myClickedPoint);
355 if (!(theEvent->buttons() & Qt::LeftButton))
358 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
359 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
360 //if (!aViewer->canDragByMouse())
363 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
364 (getCurrentOperation());
368 bool isEditing = aFOperation->isEditOperation();
369 bool aCanDrag = aViewer->canDragByMouse();
371 //if (!aViewer->canDragByMouse() && isEditing) {
372 // // Do not edit by dragging
377 // If the current widget is a selector, do nothing, it processes the mouse press
378 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
379 if(anActiveWidget && anActiveWidget->isViewerSelector()) {
384 // Use only for sketch operations
385 if (myCurrentSketch) {
386 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
389 bool isSketcher = isSketchOperation(aFOperation);
390 bool isSketchOpe = isNestedSketchOperation(aFOperation);
392 // Avoid non-sketch operations
393 if ((!isSketchOpe) && (!isSketcher))
396 // Ignore creation sketch operation
397 if ((!isSketcher) && (!isEditing))
400 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
401 storeSelection(aHasShift ? ST_SelectAndHighlightType : ST_HighlightType, myCurrentSelection);
403 if (myCurrentSelection.empty()) {
404 if (isSketchOpe && (!isSketcher))
405 // commit previous operation
406 if (!aFOperation->commit())
407 aFOperation->abort();
410 // Init flyout point for radius rotation
411 FeaturePtr aFeature = myCurrentSelection.begin().key();
413 get2dPoint(theWnd, theEvent, myCurrentPoint);
419 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
421 if (aFeature.get() != NULL) {
422 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
423 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
424 if (aSPFeature.get() &&
425 (aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID() ||
426 aSPFeature->getKind() == SketchPlugin_ConstraintAngle::ID())) {
427 DataPtr aData = aSPFeature->data();
428 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
429 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
430 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
431 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
434 } else if (isSketchOpe && isEditing) {
435 // If selected another object commit current result
436 bool aPrevLaunchingState = myIsEditLaunching;
437 /// store editing state for Edit operation in order to do not clear highlight by restart
438 /// of edit operation.
439 /// Internal edit should not be stored as editing operation as the result will be a
440 /// creation operation, where previous selection should not be used(and will be cleared)
441 myIsEditLaunching = !myModule->sketchReentranceMgr()->isInternalEditActive();
442 aFOperation->commit();
448 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
450 myIsEditLaunching = aPrevLaunchingState;
451 if (aFeature.get() != NULL) {
452 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
453 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
454 if (aSPFeature.get() &&
455 (aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID() ||
456 aSPFeature->getKind() == SketchPlugin_ConstraintAngle::ID())) {
457 DataPtr aData = aSPFeature->data();
458 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
459 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
460 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
461 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
468 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
470 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
472 aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
474 bool aWasDragging = myIsDragging;
475 myIsDragging = false;
477 if (myModule->sketchReentranceMgr()->processMouseReleased(theWnd, theEvent)) {
480 // if mouse is pressed when it was over view and at release the mouse is out of view, do nothing
481 if (!myIsMouseOverViewProcessed) {
484 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
485 //if (!aViewer->canDragByMouse())
487 ModuleBase_OperationFeature* aOp =
488 dynamic_cast<ModuleBase_OperationFeature*>(getCurrentOperation());
490 bool aStartNoDragOperation = !aViewer->canDragByMouse() && aOp->isEditOperation();
491 if (aStartNoDragOperation || myNoDragMoving) {
492 // Process edit operation without dragging
493 if (myCurrentSelection.size() > 0)
494 myNoDragMoving = !myNoDragMoving;
496 myNoDragMoving = false;
500 restoreSelection(myCurrentSelection);
501 myCurrentSelection.clear();
505 if (isNestedSketchOperation(aOp)) {
506 // Only for sketcher operations
509 /// the previous selection is lost by mouse release in the viewer(Select method), but
510 /// it is still stored in myCurrentSelection. So, it is possible to restore selection
511 /// It is important for drag(edit with mouse) of sketch entities.
512 restoreSelection(myCurrentSelection);
513 myCurrentSelection.clear();
521 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
522 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
524 aProcessor->mouseReleased(theWnd, theEvent);
527 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
529 #ifdef DEBUG_SKETCH_ENTITIES_ON_MOVE
530 CompositeFeaturePtr aSketch = activeSketch();
532 std::cout << "mouse move SKETCH FEATURES [" << aSketch->numberOfSubs() << "]:" << std::endl;
534 for (int i = 0, aNbSubs = aSketch->numberOfSubs(); i < aNbSubs; i++) {
535 //std::cout << getFeatureInfo(aSketch->subFeature(i), false) << std::endl;
536 anInfo.append(ModuleBase_Tools::objectInfo(aSketch->subFeature(i)));
538 QString anInfoStr = anInfo.join("\n");
539 qDebug(QString("%1").arg(anInfo.size()).arg(anInfoStr).toStdString().c_str());
542 if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
545 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
546 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
547 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
549 if (isNestedCreateOperation(getCurrentOperation(), activeSketch())) {
550 #ifdef DRAGGING_DEBUG
554 // 1. perform the widget mouse move functionality and display the presentation
555 // the mouse move should be processed in the widget, if it can in order to visualize correct
556 // presentation. These widgets correct the feature attribute according to the mouse position
557 ModuleBase_ModelWidget* anActiveWidget = myModule->activeWidget();
558 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
560 aProcessor->mouseMoved(theWnd, theEvent);
561 if (!myIsMouseOverViewProcessed) {
562 myIsMouseOverViewProcessed = true;
564 // the feature is to be erased here, but it is correct to call canDisplayObject because
565 // there can be additional check (e.g. editor widget in distance constraint)
566 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
567 (getCurrentOperation());
569 FeaturePtr aFeature = aFOperation->feature();
570 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
573 aDisplayer->updateViewer();
574 #ifdef DRAGGING_DEBUG
575 cout << "Mouse move processing " << t.elapsed() << endl;
578 //myClickedPoint.clear();
580 if (myIsDragging || myNoDragMoving) {
581 // 1. the current selection is saved in the mouse press method in order to restore it after
583 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
584 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
585 // deselected). This flag should be restored in the slot, processed the mouse release signal.
586 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
587 if (!aCurrentOperation)
589 if (isSketchOperation(aCurrentOperation))
590 return; // No edit operation activated
592 #ifdef DRAGGING_DEBUG
597 Handle(V3d_View) aView = theWnd->v3dView();
598 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
600 get2dPoint(theWnd, theEvent, aMousePnt);
602 std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition = std::shared_ptr<GeomAPI_Pnt2d>(
603 new GeomAPI_Pnt2d(myCurrentPoint.myCurX, myCurrentPoint.myCurY));
604 std::shared_ptr<GeomAPI_Pnt2d> aCurrentPosition = std::shared_ptr<GeomAPI_Pnt2d>(
605 new GeomAPI_Pnt2d(aMousePnt.myCurX, aMousePnt.myCurY));
607 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
608 // viewer happens by deselect/select the modified objects. The flag should be restored after
609 // the selection processing. The update viewer should be also called.
610 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
612 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
613 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
614 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
615 aLast = myCurrentSelection.end();
616 // 4. the features and attributes modification(move)
617 bool isModified = false;
618 for (; anIt != aLast; anIt++) {
619 FeaturePtr aFeature = anIt.key();
621 std::set<AttributePtr> anAttributes = anIt.value().myAttributes;
622 // Process selection by attribute: the priority to the attribute
623 if (!anAttributes.empty()) {
624 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
625 anAttLast = anAttributes.end();
626 for (; anAttIt != anAttLast; anAttIt++) {
627 AttributePtr anAttr = *anAttIt;
628 if (anAttr.get() == NULL)
630 std::string aAttrId = anAttr->id();
631 DataPtr aData = aFeature->data();
632 if (aData->isValid()) {
633 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
634 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
635 if (aPoint.get() != NULL) {
636 bool isImmutable = aPoint->setImmutable(true);
638 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage = std::shared_ptr
639 <ModelAPI_ObjectMovedMessage>(new ModelAPI_ObjectMovedMessage(this));
640 aMessage->setMovedAttribute(aPoint);
641 aMessage->setOriginalPosition(anOriginalPosition);
642 aMessage->setCurrentPosition(aCurrentPosition);
643 Events_Loop::loop()->send(aMessage);
646 aPoint->setImmutable(isImmutable);
652 // Process selection by feature
653 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
654 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
655 if (aSketchFeature) {
656 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage = std::shared_ptr
657 <ModelAPI_ObjectMovedMessage>(new ModelAPI_ObjectMovedMessage(this));
658 aMessage->setMovedObject(aFeature);
659 aMessage->setOriginalPosition(anOriginalPosition);
660 aMessage->setCurrentPosition(aCurrentPosition);
661 Events_Loop::loop()->send(aMessage);
666 // the modified state of the current operation should be updated if there are features, which
669 aCurrentOperation->onValuesChanged();
670 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
672 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
674 // 5. it is necessary to save current selection in order to restore it after the features moving
675 restoreSelection(myCurrentSelection);
676 // 6. restore the update viewer flag and call this update
677 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
678 aDisplayer->updateViewer();
680 #ifdef DRAGGING_DEBUG
681 cout << "Mouse move processing " << t.elapsed() << endl;
685 myCurrentPoint = aMousePnt;
689 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
691 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
692 (getCurrentOperation());
693 if (aFOperation && aFOperation->isEditOperation()) {
694 std::string aId = aFOperation->id().toStdString();
695 if (isDistanceOperation(aFOperation))
697 // Activate dimension value editing on double click
698 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
699 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
700 // Find corresponded widget to activate value editing
701 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
702 std::string anId = aWgt->attributeID();
703 if (anId == SketchPlugin_Constraint::VALUE() ||
704 anId == SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID() ||
705 anId == SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()) {
706 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
708 anEditor->showPopupEditor();
716 void PartSet_SketcherMgr::onApplicationStarted()
718 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
719 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
720 XGUI_Workshop* aWorkshop = aConnector->workshop();
721 PartSet_SketcherReentrantMgr* aReentranceMgr = myModule->sketchReentranceMgr();
723 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
724 if (aPropertyPanel) {
725 //connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
726 // this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
728 connect(aPropertyPanel, SIGNAL(noMoreWidgets(const std::string&)),
729 aReentranceMgr, SLOT(onNoMoreWidgets(const std::string&)));
730 //connect(aPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
731 // aReentranceMgr, SLOT(onWidgetActivated()));
734 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
735 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
736 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
738 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
739 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
740 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
743 //void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
745 //if (!myClickedPoint.myIsInitialized)
748 //ModuleBase_Operation* aOperation = getCurrentOperation();
749 // the distance constraint feature should not use the clickedd point
750 // this is workaround in order to don't throw down the flyout point value,
751 // set by execute() method of these type of features
752 //if (isDistanceOperation(aOperation))
755 //PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
757 // aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
761 void PartSet_SketcherMgr::onBeforeContextMenu()
763 myIsPopupMenuActive = true;
766 void PartSet_SketcherMgr::onAfterContextMenu()
768 myIsPopupMenuActive = false;
771 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
774 Handle(V3d_View) aView = theWnd->v3dView();
775 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
777 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
778 thePoint.setValue(aX, anY);
781 void PartSet_SketcherMgr::launchEditing()
783 if (!myCurrentSelection.empty()) {
784 FeaturePtr aFeature = myCurrentSelection.begin().key();
785 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
786 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
788 if (!aSPFeature->isExternal())
789 myModule->editFeature(aSPFeature);
791 // need to edit a feature (Projection/IntersectionPoint),
792 // which produces current External feature
793 FeaturePtr aProducerFeature = PartSet_Tools::findRefsToMeFeature(aFeature,
794 SketchPlugin_Projection::ID());
795 if (!aProducerFeature.get())
796 aProducerFeature = PartSet_Tools::findRefsToMeFeature(aFeature,
797 SketchPlugin_IntersectionPoint::ID());
798 if (aProducerFeature.get())
799 myModule->editFeature(aProducerFeature);
805 bool PartSet_SketcherMgr::sketchSolverError()
807 bool anError = false;
808 CompositeFeaturePtr aSketch = activeSketch();
810 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
811 anError = !aAttributeString->value().empty();
816 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
819 if (!theFeature.get() || !theFeature->data()->isValid())
822 CompositeFeaturePtr aSketch = activeSketch();
823 if (aSketch.get() && aSketch == theFeature) {
824 std::string aSolverError = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR())->value();
825 anError = ModuleBase_Tools::translate(aSketch->getKind(), aSolverError);
830 void PartSet_SketcherMgr::clearClickedFlags()
832 //myClickedPoint.clear();
833 myCurrentPoint.clear();
836 const QStringList& PartSet_SketcherMgr::replicationsIdList()
838 static QStringList aReplicationIds;
839 if (aReplicationIds.size() == 0) {
840 aReplicationIds << SketchPlugin_ConstraintMirror::ID().c_str();
841 aReplicationIds << SketchPlugin_MultiRotation::ID().c_str();
842 aReplicationIds << SketchPlugin_MultiTranslation::ID().c_str();
844 return aReplicationIds;
847 const QStringList& PartSet_SketcherMgr::constraintsIdList()
849 static QStringList aConstraintIds;
850 if (aConstraintIds.size() == 0) {
851 aConstraintIds << SketchPlugin_ConstraintLength::ID().c_str();
852 aConstraintIds << SketchPlugin_ConstraintDistance::ID().c_str();
853 aConstraintIds << SketchPlugin_ConstraintRigid::ID().c_str();
854 aConstraintIds << SketchPlugin_ConstraintRadius::ID().c_str();
855 aConstraintIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
856 aConstraintIds << SketchPlugin_ConstraintParallel::ID().c_str();
857 aConstraintIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
858 aConstraintIds << SketchPlugin_ConstraintVertical::ID().c_str();
859 aConstraintIds << SketchPlugin_ConstraintEqual::ID().c_str();
860 aConstraintIds << SketchPlugin_ConstraintTangent::ID().c_str();
861 aConstraintIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
862 aConstraintIds << SketchPlugin_ConstraintAngle::ID().c_str();
863 aConstraintIds << SketchPlugin_ConstraintCollinear::ID().c_str();
864 aConstraintIds << SketchPlugin_ConstraintMiddle::ID().c_str();
865 aConstraintIds << SketchPlugin_ConstraintMirror::ID().c_str();
866 aConstraintIds << SketchPlugin_MultiTranslation::ID().c_str();
867 aConstraintIds << SketchPlugin_MultiRotation::ID().c_str();
868 aConstraintIds << SketchPlugin_ConstraintDistanceAlongDir::ID().c_str();
869 aConstraintIds << SketchPlugin_ConstraintDistanceHorizontal::ID().c_str();
870 aConstraintIds << SketchPlugin_ConstraintDistanceVertical::ID().c_str();
872 return aConstraintIds;
875 void PartSet_SketcherMgr::sketchSelectionModes(const CompositeFeaturePtr& theSketch,
878 if (!theSketch.get() || !PartSet_Tools::sketchPlane(theSketch).get())
881 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
882 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
883 theModes.append(SketcherPrs_Tools::Sel_Constraint);
884 theModes.append(TopAbs_VERTEX);
885 theModes.append(TopAbs_EDGE);
888 Handle(AIS_InteractiveObject) PartSet_SketcherMgr::createPresentation(const ResultPtr& theResult)
890 Handle(AIS_InteractiveObject) aPrs;
892 FeaturePtr aFeature = ModelAPI_Feature::feature(theResult);
893 if (aFeature.get() && aFeature->getKind() == SketchPlugin_Sketch::ID()) {
894 aPrs = new PartSet_ResultSketchPrs(theResult);
899 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
901 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
904 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation) const
906 bool aNestedSketch = false;
908 FeaturePtr anActiveSketch = activeSketch();
909 if (anActiveSketch.get() && theOperation) {
910 ModuleBase_Operation* aSketchOperation = operationMgr()->findOperation(
911 anActiveSketch->getKind().c_str());
912 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
914 if (aSketchOperation && aFOperation) {
915 FeaturePtr aFeature = aFOperation->feature();
916 if (aFeature.get()) {
917 QStringList aGrantedOpIds = aSketchOperation->grantedOperationIds();
918 aNestedSketch = aGrantedOpIds.contains(aFeature->getKind().c_str());
922 return aNestedSketch;
925 bool PartSet_SketcherMgr::isNestedSketchFeature(const QString& theFeatureKind) const
927 bool aNestedSketch = false;
929 FeaturePtr anActiveSketch = activeSketch();
930 if (anActiveSketch.get()) {
931 ModuleBase_Operation* aSketchOperation = operationMgr()->findOperation(
932 anActiveSketch->getKind().c_str());
933 if (aSketchOperation) {
934 QStringList aGrantedOpIds = aSketchOperation->grantedOperationIds();
935 aNestedSketch = aGrantedOpIds.contains(theFeatureKind);
938 return aNestedSketch;
941 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation,
942 const CompositeFeaturePtr& theSketch) const
944 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
946 return aFOperation && !aFOperation->isEditOperation() &&
947 isNestedSketchOperation(aFOperation);
950 bool PartSet_SketcherMgr::isNestedEditOperation(ModuleBase_Operation* theOperation,
951 const CompositeFeaturePtr& theSketch) const
953 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
955 return aFOperation && aFOperation->isEditOperation() &&
956 isNestedSketchOperation(aFOperation);
959 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
961 return (theId == SketchPlugin_Line::ID()) ||
962 (theId == SketchPlugin_Point::ID()) ||
963 (theId == SketchPlugin_Arc::ID()) ||
964 (theId == SketchPlugin_Circle::ID()) ||
965 (theId == SketchPlugin_Ellipse::ID()) ||
966 (theId == SketchPlugin_EllipticArc::ID());
969 bool PartSet_SketcherMgr::isExternalFeature(const FeaturePtr& theFeature)
971 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
972 std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
973 return aSPFeature.get() && aSPFeature->isExternal();
976 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
978 std::string anId = theOperation ? theOperation->id().toStdString() : "";
980 return isDistanceKind(anId);
983 bool PartSet_SketcherMgr::isDistanceKind(std::string& theKind)
985 return (theKind == SketchPlugin_ConstraintLength::ID()) ||
986 (theKind == SketchPlugin_ConstraintDistance::ID()) ||
987 (theKind == SketchPlugin_ConstraintRadius::ID()) ||
988 (theKind == SketchPlugin_ConstraintAngle::ID()) ||
989 (theKind == SketchPlugin_ConstraintDistanceHorizontal::ID()) ||
990 (theKind == SketchPlugin_ConstraintDistanceVertical::ID()) ||
991 (theKind == SketchPlugin_ConstraintDistanceAlongDir::ID());
994 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
996 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
997 (getCurrentOperation());
1001 SketcherPrs_Tools::setPixelRatio(ModuleBase_Tools::currentPixelRatio());
1003 myModule->onViewTransformed();
1005 // Display all sketcher sub-Objects
1006 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
1007 double aSizeOfView = 0;
1008 std::shared_ptr<GeomAPI_Pnt> aCentralPoint;
1009 if (aFOperation->isEditOperation() &&
1010 mySketchPlane->getDefaultSizeOfView(myCurrentSketch, aSizeOfView, aCentralPoint)) {
1011 mySketchPlane->setSizeOfView(aSizeOfView, true, aCentralPoint);
1014 mySketchPlane->createSketchPlane(myCurrentSketch, myModule->workshop());
1015 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
1017 // Hide sketcher result
1018 std::list<ResultPtr> aResults = myCurrentSketch->results();
1019 std::list<ResultPtr>::const_iterator aIt;
1020 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1021 (*aIt)->setDisplayed(false);
1023 myCurrentSketch->setDisplayed(false);
1025 // Remove invalid sketch entities
1026 std::set<FeaturePtr> anInvalidFeatures;
1027 ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
1028 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
1029 for (int i = 0; i < aNumberOfSubs; i++) {
1030 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1031 if (aFeature.get()) {
1032 if (!aFactory->validate(aFeature))
1033 anInvalidFeatures.insert(aFeature);
1036 if (!anInvalidFeatures.empty()) {
1037 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1038 ModelAPI_Tools::findAllReferences(anInvalidFeatures, aReferences, false);
1040 std::set<FeaturePtr>::const_iterator anIt = anInvalidFeatures.begin(),
1041 aLast = anInvalidFeatures.end();
1042 // separate features to references to parameter features and references to others
1043 QStringList anInvalidFeatureNames;
1044 for (; anIt != aLast; anIt++) {
1045 FeaturePtr aFeature = *anIt;
1047 anInvalidFeatureNames.append(aFeature->name().c_str());
1049 std::string aPrefixInfo = QString("Invalid features of the sketch will be deleted: %1.\n\n").
1050 arg(anInvalidFeatureNames.join(", ")).toStdString().c_str();
1051 std::set<FeaturePtr> aFeatureRefsToDelete;
1052 if (ModuleBase_Tools::askToDelete(anInvalidFeatures, aReferences, aConnector->desktop(),
1053 aFeatureRefsToDelete, aPrefixInfo)) {
1054 if (!aFeatureRefsToDelete.empty())
1055 anInvalidFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1056 ModelAPI_Tools::removeFeatures(anInvalidFeatures, true);
1057 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
1058 // TODO: call the next method in the XGUI_OperationMgr::onOperationStarted().
1059 workshop()->errorMgr()->updateAcceptAllAction(myCurrentSketch);
1063 // update state of overconstraint listener should be done before sketch features/results
1064 // display (as the display will ask custom color from the listener)
1065 myModule->overconstraintListener()->setActive(true);
1066 // Display sketcher objects
1068 Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1069 const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
1070 aNumberOfSubs = myCurrentSketch->numberOfSubs();
1071 for (int i = 0; i < aNumberOfSubs; i++) {
1072 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1073 #ifdef DEBUG_SKETCHER_ENTITIES
1074 anInfo.append(ModuleBase_Tools::objectInfo(aFeature));
1076 std::list<ResultPtr> aResults = aFeature->results();
1077 std::list<ResultPtr>::const_iterator aIt;
1078 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1079 if ((*aIt)->isDisplayed())
1080 // Display object if it was created outside of GUI
1081 aECreator->sendUpdated((*aIt), EVENT_DISP);
1083 (*aIt)->setDisplayed(true);
1085 if (aFeature->isDisplayed())
1086 aECreator->sendUpdated(aFeature, EVENT_DISP);
1088 aFeature->setDisplayed(true);
1090 #ifdef DEBUG_SKETCHER_ENTITIES
1091 QString anInfoStr = anInfo.join(";\t");
1092 qDebug(QString("startSketch: %1, %2").arg(anInfo.size()).arg(anInfoStr).toStdString().c_str());
1095 bool aHasPlane = false;
1096 std::shared_ptr<GeomAPI_Pln> aPln;
1097 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
1098 Handle(SelectMgr_Filter) aFilter = myModule->selectionFilter(SF_SketchPlaneFilter);
1099 if (!aFilter.IsNull())
1100 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(aPln);
1102 workshop()->selectionActivate()->updateSelectionFilters();
1103 workshop()->selectionActivate()->updateSelectionModes();
1105 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1107 myExternalPointsMgr = new PartSet_ExternalPointsMgr(myModule->workshop(), myCurrentSketch);
1109 workshop()->viewer()->set2dMode(true);
1111 PartSet_Fitter* aFitter = new PartSet_Fitter(this);
1112 myModule->workshop()->viewer()->setFitter(aFitter);
1115 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
1117 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
1118 PartSet_Fitter* aFitter = (PartSet_Fitter*)myModule->workshop()->viewer()->fitter();
1119 myModule->workshop()->viewer()->setFitter(0);
1122 myIsMouseOverWindow = false;
1123 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
1124 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
1125 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
1127 if (myExternalPointsMgr) {
1128 delete myExternalPointsMgr;
1129 myExternalPointsMgr = 0;
1131 onShowPoints(false);
1133 DataPtr aData = myCurrentSketch->data();
1134 if (!aData->isValid()) {
1135 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1136 // The sketch was aborted
1137 myCurrentSketch = CompositeFeaturePtr();
1138 mySketchPlane->eraseSketchPlane(myModule->workshop());
1140 // Erase all sketcher objects
1141 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1142 foreach (ObjectPtr aObj, aObjects) {
1143 DataPtr aObjData = aObj->data();
1144 if (!aObjData->isValid())
1145 aObj->setDisplayed(false);
1149 // Hide all sketcher sub-Objects
1150 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
1151 for (int i = 0; i < aNumberOfSubs; i++) {
1152 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1153 std::list<ResultPtr> aResults = aFeature->results();
1154 std::list<ResultPtr>::const_iterator aIt;
1155 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1156 (*aIt)->setDisplayed(false);
1158 aFeature->setDisplayed(false);
1160 // Display sketcher result
1161 std::list<ResultPtr> aResults = myCurrentSketch->results();
1162 std::list<ResultPtr>::const_iterator aIt;
1163 Events_Loop* aLoop = Events_Loop::loop();
1164 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1166 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1168 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1169 if (!aFOperation->isDisplayedOnStart(*aIt)) {
1170 (*aIt)->setDisplayed(true);
1171 // this display event is needed because sketch already may have "displayed" state,
1172 // but not displayed while it is still active (issue 613, abort of existing sketch)
1173 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
1176 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
1177 myCurrentSketch->setDisplayed(true);
1179 myCurrentSketch = CompositeFeaturePtr();
1180 mySketchPlane->eraseSketchPlane(myModule->workshop());
1182 Events_Loop::loop()->flush(aDispEvent);
1184 workshop()->selectionActivate()->updateSelectionFilters();
1185 workshop()->selectionActivate()->updateSelectionModes();
1186 workshop()->viewer()->set2dMode(false);
1189 //void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
1191 // if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
1192 // QCursor* aCurrentCursor = QApplication::overrideCursor();
1193 // if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
1194 // QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
1195 //#ifdef DEBUG_CURSOR
1196 // qDebug("startNestedSketch() : Qt::CrossCursor");
1202 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
1204 myIsMouseOverViewProcessed = true;
1205 operationMgr()->onValidateOperation();
1206 // when sketch nested operation is stopped the cursor should be restored unconditionally
1207 //if (canChangeCursor(theOperation)) {
1208 //QApplication::restoreOverrideCursor();
1210 qDebug("stopNestedSketch() : None");
1213 /// improvement to deselect automatically all eventual selected objects, when
1214 // returning to the neutral point of the Sketcher
1215 bool isClearSelectionPossible = true;
1216 if (myIsEditLaunching) {
1217 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1220 FeaturePtr aFeature = aFOperation->feature();
1221 if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
1222 isClearSelectionPossible = false;
1226 if (isClearSelectionPossible)
1227 workshop()->selector()->clearSelection();
1228 if (myPointsHighlight.size())
1232 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
1234 if (isNestedCreateOperation(theOperation, activeSketch())) {
1235 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1238 FeaturePtr aFeature = aFOperation->feature();
1239 // it is necessary to check the the feature data validity because
1240 // some kind of features are removed by an operation commit(the macro state of a feature)
1241 if (aFeature.get() && aFeature->data()->isValid()) {
1242 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
1248 bool PartSet_SketcherMgr::sketchSelectionFilter(const ModuleBase_SelectionFilterType theFilterType)
1250 return mySelectionFilterTypes.find(theFilterType) != mySelectionFilterTypes.end();
1253 void PartSet_SketcherMgr::registerSelectionFilter(
1254 const ModuleBase_SelectionFilterType theFilterType, const Handle(SelectMgr_Filter)& theFilter)
1256 mySelectionFilterTypes.insert(theFilterType);
1257 myModule->registerSelectionFilter(theFilterType, theFilter);
1260 bool PartSet_SketcherMgr::operationActivatedByPreselection()
1262 bool isOperationStopped = false;
1263 ModuleBase_Operation* anOperation = getCurrentOperation();
1264 if(anOperation && isNestedSketchOperation(anOperation)) {
1265 // Set final definitions if they are necessary
1266 //propertyPanelDefined(aOperation);
1267 /// Commit sketcher operations automatically
1268 /// distance operation are able to show popup editor to modify the distance value
1269 /// after entering the value, the operation should be committed/aborted(by Esc key)
1270 bool aCanCommitOperation = true;
1271 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1273 if (aFOperation && PartSet_SketcherMgr::isDistanceOperation(aFOperation)) {
1274 bool aValueAccepted = setDistanceValueByPreselection(anOperation, myModule->workshop(),
1275 aCanCommitOperation);
1276 if (!aValueAccepted)
1277 return isOperationStopped;
1280 if (aCanCommitOperation)
1281 isOperationStopped = anOperation->commit();
1283 anOperation->abort();
1284 isOperationStopped = true;
1287 return isOperationStopped;
1290 bool PartSet_SketcherMgr::canUndo() const
1292 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1295 bool PartSet_SketcherMgr::canRedo() const
1297 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1300 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1302 bool aCanErase = true;
1303 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1304 if (myCurrentSketch.get()) {
1305 return !isObjectOfSketch(theObject);
1310 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1312 bool aCanDisplay = true;
1314 bool aHasActiveSketch = activeSketch().get() != NULL;
1315 if (aHasActiveSketch) {
1316 // 1. the sketch feature should not be displayed during the sketch active operation
1317 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1318 // nested features can be visualized
1319 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1320 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1321 aCanDisplay = false;
1323 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1324 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1325 /// some sketch entities should be never shown, e.g. projection feature
1326 if (aSketchFeature.get())
1327 aCanDisplay = aSketchFeature->canBeDisplayed();
1329 else { // there are no an active sketch
1330 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1331 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1332 if (aFeature.get() != NULL) {
1333 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1334 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1335 if (aSketchFeature.get()) {
1336 aCanDisplay = false;
1341 // 3. the method should not filter the objects, which are not related to the current operation.
1342 // The object is filtered just if it is a current operation feature or this feature result
1344 bool isObjectFound = false;
1345 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1346 (getCurrentOperation());
1348 FeaturePtr aFeature = aFOperation->feature();
1349 if (aFeature.get()) {
1350 std::list<ResultPtr> aResults = aFeature->results();
1351 if (theObject == aFeature)
1352 isObjectFound = true;
1354 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1355 for (; anIt != aLast && !isObjectFound; anIt++) {
1356 isObjectFound = *anIt == theObject;
1361 if (isObjectFound) {
1362 // 4. For created nested feature operation do not display the created feature if
1363 // the mouse curstor leaves the OCC window.
1364 // The correction cases, which ignores this condition:
1365 // a. the property panel values modification
1366 // b. the popup menu activated
1367 // c. widget editor control
1368 #ifndef DEBUG_DO_NOT_BY_ENTER
1369 if (isNestedCreateOperation(getCurrentOperation(), activeSketch())) {
1370 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1371 ModuleBase_WidgetEditor* anEditorWdg =
1372 anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1373 // the active widget editor should not influence here. The presentation should be visible
1374 // always when this widget is active.
1375 if (!anEditorWdg && !myIsPopupMenuActive) {
1376 // during a nested create operation, the feature is redisplayed only
1377 // if the mouse over view
1378 // of there was a value modified in the property panel after the mouse left the view
1379 aCanDisplay = canDisplayCurrentCreatedFeature();
1386 // checks the sketcher constraints visibility according to active sketch check box states
1388 bool aProcessed = false;
1389 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1390 if (aFeature.get()) {
1391 bool aConstraintDisplayed = canDisplayConstraint(aFeature, PartSet_Tools::Any, aProcessed);
1393 aCanDisplay = aConstraintDisplayed;
1400 bool PartSet_SketcherMgr::canDisplayConstraint(const FeaturePtr& theFeature,
1401 const PartSet_Tools::ConstraintVisibleState& theState,
1402 bool& isProcessed) const
1404 bool aSwitchedOn = true;
1406 const QStringList& aConstrIds = constraintsIdList();
1408 std::string aKind = theFeature->getKind();
1409 if (aConstrIds.contains(QString(aKind.c_str()))) {
1410 bool isTypedConstraint = false;
1413 case PartSet_Tools::Dimensional: {
1414 bool isDistance = isDistanceKind(aKind);
1417 aSwitchedOn = myIsConstraintsShown[theState];
1421 case PartSet_Tools::Geometrical: {
1422 bool isGeometrical = !isDistanceKind(aKind);
1423 if (isGeometrical) {
1425 aSwitchedOn = myIsConstraintsShown[theState];
1429 case PartSet_Tools::Any: {
1431 bool isDistance = isDistanceKind(aKind);
1433 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Dimensional];
1435 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Geometrical];
1445 /*void PartSet_SketcherMgr::processHiddenObject(const std::list<ObjectPtr>& theObjects)
1447 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1448 (getCurrentOperation());
1449 if (aFOperation && myCurrentSketch.get()) {
1450 // find results of the current operation
1451 // these results should not be proposed to be deleted
1452 FeaturePtr anOperationFeature = aFOperation->feature();
1453 std::list<ResultPtr> anOperationResultList = anOperationFeature->results();
1454 std::set<ResultPtr> anOperationResults;
1455 std::list<ResultPtr>::const_iterator aRIt = anOperationResultList.begin(),
1456 aRLast = anOperationResultList.end();
1457 for (; aRIt != aRLast; aRIt++)
1458 anOperationResults.insert(*aRIt);
1460 std::set<FeaturePtr> anObjectsToBeDeleted;
1461 QStringList anObjectsToBeDeletedNames;
1462 std::list<ObjectPtr>::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1463 for (; anIt != aLast; anIt++) {
1464 ObjectPtr anObject = *anIt;
1465 bool aCanErase = true;
1466 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1467 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1468 // the result is found between current feature results
1469 if (anOperationResults.find(aResult) != anOperationResults.end())
1472 if (aResult.get()) {
1473 // Display sketcher objects
1474 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1475 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1476 std::list<ResultPtr> aResults = aFeature->results();
1477 std::list<ResultPtr>::const_iterator anIt;
1478 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1479 aCanErase = *anIt != aResult;
1484 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1485 if (aFeature.get() && anObjectsToBeDeleted.find(aFeature) == anObjectsToBeDeleted.end()) {
1486 anObjectsToBeDeleted.insert(aFeature);
1487 anObjectsToBeDeletedNames.append(aFeature->name().c_str());
1491 if (!anObjectsToBeDeleted.empty()) {
1492 QString aFeatureNames = anObjectsToBeDeletedNames.join(", ");
1493 QString aMessage = tr("The following features have incorrect presentation and \
1494 will be hidden: %1. Would you like to delete them?")
1495 .arg(aFeatureNames);
1496 int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Features hide"),
1497 aMessage, QMessageBox::Ok | QMessageBox::Cancel,
1498 QMessageBox::Cancel);
1499 if (anAnswer == QMessageBox::Ok) {
1500 QObjectPtrList anObjects;
1501 std::set<FeaturePtr>::const_iterator anIt = anObjectsToBeDeleted.begin(),
1502 aLast = anObjectsToBeDeleted.end();
1503 for (; anIt != aLast; anIt++)
1504 anObjects.append(*anIt);
1505 SessionPtr aMgr = ModelAPI_Session::get();
1506 DocumentPtr aDoc = aMgr->activeDocument();
1507 bool aIsOp = aMgr->isOperation();
1509 aMgr->startOperation();
1510 workshop()->deleteFeatures(anObjects);
1511 //static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
1512 //static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
1513 //Events_Loop::loop()->flush(aDeletedEvent);
1514 //Events_Loop::loop()->flush(aRedispEvent);
1517 aMgr->finishOperation();
1523 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1525 bool aCanDisplay = myIsMouseOverWindow;
1527 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1529 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1534 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1536 return isNestedCreateOperation(theOperation, activeSketch()) ||
1537 myModule->sketchReentranceMgr()->isInternalEditActive();
1540 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
1542 return myIsConstraintsShown;
1545 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1547 bool isFoundObject = false;
1549 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1550 if (anObjectFeature.get()) {
1551 int aSize = myCurrentSketch->numberOfSubs();
1552 for (int i = 0; i < aSize && !isFoundObject; i++) {
1553 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1554 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1557 return isFoundObject;
1560 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePlane)
1562 Handle(SelectMgr_Filter) aFilter = myModule->selectionFilter(SF_SketchPlaneFilter);
1563 if (!aFilter.IsNull())
1564 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(thePlane);
1566 workshop()->selectionActivate()->updateSelectionModes();
1569 bool PartSet_SketcherMgr::setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
1570 ModuleBase_IWorkshop* theWorkshop,
1571 bool& theCanCommitOperation)
1573 bool isValueAccepted = false;
1574 theCanCommitOperation = false;
1576 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1578 FeaturePtr aFeature = aFOperation->feature();
1579 // editor is shown only if all attribute references are filled by preseletion
1580 bool anAllRefAttrInitialized = true;
1582 std::list<AttributePtr> aRefAttrs = aFeature->data()->attributes(
1583 ModelAPI_AttributeRefAttr::typeId());
1584 std::list<AttributePtr>::const_iterator anIt = aRefAttrs.begin(), aLast = aRefAttrs.end();
1585 for (; anIt != aLast && anAllRefAttrInitialized; anIt++) {
1586 anAllRefAttrInitialized = (*anIt)->isInitialized();
1588 if (anAllRefAttrInitialized) {
1589 // Activate dimension value editing on double click
1590 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
1591 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
1592 // Find corresponded widget to activate value editing
1593 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
1594 if (aWgt->attributeID() == "ConstraintValue") {
1595 // the featue should be displayed in order to find the AIS text position,
1596 // the place where the editor will be shown
1597 aFeature->setDisplayed(true);
1598 /// the execute is necessary to perform in the feature compute for flyout position
1599 aFeature->execute();
1601 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1602 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1604 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
1606 int aX = 0, anY = 0;
1608 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(theWorkshop);
1609 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1610 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
1611 Handle(AIS_InteractiveObject) anAISIO;
1612 if (anAIS.get() != NULL) {
1613 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1615 if (anAIS.get() != NULL) {
1616 Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1618 if (!anAISIO.IsNull()) {
1619 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
1620 if (!aDim.IsNull()) {
1621 gp_Pnt aPosition = aDim->GetTextPosition();
1623 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
1624 Handle(V3d_View) aView = aViewer->activeView();
1626 aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
1628 QWidget* aViewPort = aViewer->activeViewPort();
1629 QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
1634 anEditor->setCursorPosition(aX, anY);
1635 isValueAccepted = anEditor->showPopupEditor(false);
1636 theCanCommitOperation = true;
1642 return isValueAccepted;
1645 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1646 const FeaturePtr& theSketch,
1647 ModuleBase_IWorkshop* theWorkshop,
1648 const FeatureToSelectionMap& theSelection,
1649 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1651 if (theFeature.get() == NULL)
1654 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1655 SelectionInfo anInfo = anIt.value();
1656 std::set<AttributePtr> aSelectedAttributes = anInfo.myAttributes;
1657 std::set<ResultPtr> aSelectedResults = anInfo.myResults;
1659 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1661 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1662 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1664 // 1. found the feature's owners. Check the AIS objects of the constructions
1665 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1666 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1667 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1669 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1670 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1671 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1672 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1673 if (!anOwner.IsNull())
1674 theOwnersToSelect.Add(anOwner);
1678 // 2. found the feature results's owners
1679 std::list<ResultPtr> aResults = theFeature->results();
1680 std::list<ResultPtr>::const_iterator aIt;
1682 bool isSameShape = false;
1683 if (aResults.size() > 0) {
1684 ResultPtr aFirstResult = theFeature->firstResult();
1685 if (aFirstResult.get() && aFirstResult->shape().get()) {
1686 TopoDS_Shape aFirstShape = aFirstResult->shape()->impl<TopoDS_Shape>();
1687 isSameShape = aFirstShape.IsEqual(anInfo.myFirstResultShape);
1690 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1691 ResultPtr aResult = *aIt;
1692 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1693 if (aAISObj.get() == NULL)
1695 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1697 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1698 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1699 bool aFoundLocalShape = false;
1700 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1701 Handle(StdSelect_BRepOwner) anOwner =
1702 Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1703 if ( anOwner.IsNull() || !anOwner->HasShape() || theOwnersToSelect.FindIndex(anOwner))
1705 const TopoDS_Shape& aShape = anOwner->Shape();
1706 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1707 if (aShapeType == TopAbs_VERTEX) {
1708 AttributePtr aPntAttr =
1709 PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1710 if (aPntAttr.get() != NULL &&
1711 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end())
1712 theOwnersToSelect.Add(anOwner);
1713 else if (isSameShape && anInfo.myLocalSelectedShapes.Contains(aShape)) {
1714 theOwnersToSelect.Add(anOwner);
1717 else if (aShapeType == TopAbs_EDGE) {
1718 if (isSameShape && anInfo.myLocalSelectedShapes.Contains(aShape)) {
1719 // try to restore local selection on Shape result
1720 // we can do this only if the shape was not changed
1721 theOwnersToSelect.Add(anOwner);
1722 aFoundLocalShape = true;
1727 if (!aFoundLocalShape) {
1728 // result owners are put in the list of selection only if local selected shapes were not
1730 if (aSelectedResults.find(aResult) != aSelectedResults.end()) {
1731 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1732 Handle(StdSelect_BRepOwner) anOwner =
1733 Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1734 if ( anOwner.IsNull() || !anOwner->HasShape() || theOwnersToSelect.FindIndex(anOwner))
1736 // select whole result
1737 theOwnersToSelect.Add(anOwner);
1744 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
1745 const bool isToConnect)
1747 //Temporary commented as we do not modify values in property panel
1749 //connect(theWidget, SIGNAL(beforeValuesChanged()),
1750 // this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1751 //connect(theWidget, SIGNAL(afterValuesChanged()),
1752 // this, SLOT(onAfterValuesChangedInPropertyPanel()));
1753 connect(theWidget, SIGNAL(afterValuesChanged()),
1754 myModule->sketchReentranceMgr(), SLOT(onAfterValuesChangedInPropertyPanel()));
1757 //disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1758 // this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1759 //disconnect(theWidget, SIGNAL(afterValuesChanged()),
1760 // this, SLOT(onAfterValuesChangedInPropertyPanel()));
1761 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1762 myModule->sketchReentranceMgr(), SLOT(onAfterValuesChangedInPropertyPanel()));
1766 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1768 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1769 (getCurrentOperation());
1771 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1772 isNestedSketchOperation(aFOperation) &&
1773 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1774 FeaturePtr aFeature = aFOperation->feature();
1775 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1780 void PartSet_SketcherMgr::customizePresentation(const ObjectPtr& theObject)
1782 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1783 (getCurrentOperation());
1784 if (aFOperation && (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1785 isNestedSketchOperation(aFOperation)))
1786 SketcherPrs_Tools::sendExpressionShownEvent(myIsConstraintsShown[PartSet_Tools::Expressions]);
1788 // update entities selection priorities
1789 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1790 if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
1791 // update priority for feature
1792 updateSelectionPriority(aFeature, aFeature);
1793 // update priority for results of the feature
1794 std::list<ResultPtr> aResults = aFeature->results();
1795 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLastIt = aResults.end();
1796 for (; anIt != aLastIt; anIt++)
1797 updateSelectionPriority(*anIt, aFeature);
1801 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1803 return myModule->workshop()->currentOperation();
1806 //**************************************************************
1807 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1809 ModuleBase_ModelWidget* aWidget = 0;
1810 ModuleBase_Operation* anOperation = getCurrentOperation();
1812 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1814 aWidget = aPanel->activeWidget();
1819 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1820 const bool isEditOperation,
1821 const bool isToDisplay,
1822 const bool isFlushRedisplay)
1824 #ifdef DEBUG_DO_NOT_BY_ENTER
1828 if (isEditOperation || !theFeature.get())
1831 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1832 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1834 // 1. change visibility of the object itself, here the presentable object is processed,
1835 // e.g. constraints features
1836 //FeaturePtr aFeature = aFOperation->feature();
1837 std::list<ResultPtr> aResults = theFeature->results();
1839 theFeature->setDisplayed(true);
1841 theFeature->setDisplayed(false);
1843 // change visibility of the object results, e.g. non-constraint features
1844 std::list<ResultPtr>::const_iterator aIt;
1845 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1847 (*aIt)->setDisplayed(true);
1850 (*aIt)->setDisplayed(false);
1853 if (isFlushRedisplay)
1854 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1857 void PartSet_SketcherMgr::storeSelection(const SelectionType theType,
1858 PartSet_SketcherMgr::FeatureToSelectionMap& theCurrentSelection)
1860 if (!myCurrentSketch.get())
1863 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1864 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1865 QList<ModuleBase_ViewerPrsPtr> aStoredPrs;
1867 if (theType == ST_HighlightType || theType == ST_SelectAndHighlightType)
1868 aStoredPrs = aSelect->getHighlighted();
1870 QList<FeaturePtr> aFeatureList;
1871 if (theType == ST_SelectAndHighlightType || theType == ST_SelectType) {
1872 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected(
1873 ModuleBase_ISelection::AllControls);
1874 aStoredPrs.append(aSelected);
1877 // 1. it is necessary to save current selection in order to restore it after the features moving
1878 theCurrentSelection.clear();
1880 QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = aStoredPrs.begin(),
1881 aLast = aStoredPrs.end();
1883 CompositeFeaturePtr aSketch = activeSketch();
1884 for (; anIt != aLast; anIt++) {
1885 ModuleBase_ViewerPrsPtr aPrs = *anIt;
1886 ObjectPtr anObject = aPrs->object();
1887 if (!anObject.get())
1890 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1891 FeaturePtr aFeature;
1893 aFeature = ModelAPI_Feature::feature(aResult);
1895 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1897 if (!aFeature.get())
1900 std::set<AttributePtr> aSelectedAttributes;
1901 std::set<ResultPtr> aSelectedResults;
1902 SelectionInfo anInfo;
1903 if (theCurrentSelection.find(aFeature) != theCurrentSelection.end())
1904 anInfo = theCurrentSelection.find(aFeature).value();
1906 TopoDS_Shape aFirstShape;
1907 ResultPtr aFirstResult = aFeature->firstResult();
1908 if (aFirstResult.get() && aFirstResult->shape().get())
1909 aFirstShape = aFirstResult->shape()->impl<TopoDS_Shape>();
1910 anInfo.myFirstResultShape = aFirstShape;
1911 Handle(SelectMgr_EntityOwner) anOwner = aPrs->owner();
1912 if (aResult.get()) {
1913 getAttributesOrResults(anOwner, aFeature, aSketch, aResult,
1914 anInfo.myAttributes, anInfo.myResults, anInfo.myLocalSelectedShapes);
1917 std::list<ResultPtr> aResults = aFeature->results();
1918 std::list<ResultPtr>::const_iterator aIt;
1919 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1920 ResultPtr aResult = *aIt;
1921 getAttributesOrResults(anOwner, aFeature, aSketch, aResult,
1922 anInfo.myAttributes, anInfo.myResults, anInfo.myLocalSelectedShapes);
1925 theCurrentSelection[aFeature] = anInfo;
1927 //qDebug(QString(" storeSelection: %1").arg(theCurrentSelection.size()).toStdString().c_str());
1930 void PartSet_SketcherMgr::restoreSelection(
1931 PartSet_SketcherMgr::FeatureToSelectionMap& theCurrentSelection)
1933 if (!myCurrentSketch.get())
1936 //qDebug(QString("restoreSelection: %1").arg(theCurrentSelection.size()).toStdString().c_str());
1937 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1938 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1939 FeatureToSelectionMap::const_iterator aSIt = theCurrentSelection.begin(),
1940 aSLast = theCurrentSelection.end();
1941 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1942 anOwnersToSelect.Clear();
1943 for (; aSIt != aSLast; aSIt++) {
1944 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, theCurrentSelection,
1947 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1950 void PartSet_SketcherMgr::onShowConstraintsToggle(int theType, bool theState)
1952 PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
1954 updateBySketchParameters(aType, theState);
1957 void PartSet_SketcherMgr::updateBySketchParameters(
1958 const PartSet_Tools::ConstraintVisibleState& theType,
1961 if (myCurrentSketch.get() == NULL)
1964 bool aPrevState = myIsConstraintsShown[theType];
1965 myIsConstraintsShown[theType] = theState;
1968 case PartSet_Tools::Geometrical:
1969 case PartSet_Tools::Dimensional: {
1970 if (aPrevState != theState) {
1971 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1972 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1973 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
1974 for (int i = 0; i < aNumberOfSubs; i++) {
1975 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1976 bool aProcessed = false;
1977 bool aConstraintDisplayed = canDisplayConstraint(aSubFeature, theType, aProcessed);
1979 aSubFeature->setDisplayed(aConstraintDisplayed);
1981 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1985 case PartSet_Tools::Expressions: {
1986 if (aPrevState != theState) {
1987 /// call all sketch features redisplay, the expression state will be corrected in customize
1988 /// of distance presentation
1989 Events_ID anEventId = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1990 PartSet_Tools::sendSubFeaturesEvent(myCurrentSketch, anEventId);
1997 void PartSet_SketcherMgr::updateSelectionPriority(ObjectPtr theObject,
1998 FeaturePtr theFeature)
2000 if (!theObject.get() || !theFeature.get())
2003 AISObjectPtr anAIS = workshop()->displayer()->getAISObject(theObject);
2004 Handle(AIS_InteractiveObject) anAISIO;
2005 if (anAIS.get() != NULL) {
2006 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
2009 if (!anAISIO.IsNull()) { // the presentation for the object is visualized
2010 int anAdditionalPriority = 0;
2012 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
2013 std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
2014 if (aSPFeature.get() != NULL) {
2016 // 2. Simple segments
2017 // 3. External objects (violet color)
2018 // 4. Auxiliary segments (dotted)
2019 // StdSelect_BRepSelectionTool::Load uses priority calculating:
2020 // Standard_Integer aPriority =
2021 // (thePriority == -1) ? GetStandardPriority (theShape, theType) : thePriority;
2022 // Priority of Vertex is 8, edge(segment) is 7.
2023 // It might be not corrected as provides the condition above.
2024 bool isExternal = aSPFeature->isExternal();
2025 bool isAuxiliary = PartSet_Tools::isAuxiliarySketchEntity(aSPFeature);
2027 if (!isExternal && !isAuxiliary)
2028 anAdditionalPriority = 30;
2031 anAdditionalPriority = 20;
2032 // auxiliary feature
2034 anAdditionalPriority = 10; /// auxiliary objects should have less priority that
2035 // edges/vertices of local selection on not-sketch objects
2037 Handle(ModuleBase_ResultPrs) aResult = Handle(ModuleBase_ResultPrs)::DownCast(anAISIO);
2038 if (!aResult.IsNull()) {
2039 aResult->setAdditionalSelectionPriority(anAdditionalPriority);
2045 XGUI_Workshop* PartSet_SketcherMgr::workshop() const
2047 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
2048 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
2049 return aConnector->workshop();
2052 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
2054 return workshop()->operationMgr();
2057 void PartSet_SketcherMgr::onShowPoints(bool toShow)
2059 if (!myCurrentSketch.get())
2061 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
2062 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
2063 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
2065 bool aToUpdate = false;
2067 std::list<ResultPtr> aFreePoints = SketcherPrs_Tools::getFreePoints(myCurrentSketch);
2069 // Delete obsolete presentations
2070 std::list<ResultPtr> aDelList;
2071 foreach(ResultPtr aObj, myPointsHighlight.keys()) {
2072 bool aFound = (std::find(aFreePoints.begin(), aFreePoints.end(), aObj) != aFreePoints.end());
2074 aDelList.push_back(aObj);
2076 foreach(ResultPtr aObj, aDelList) {
2077 aContext->Remove(myPointsHighlight[aObj], false);
2079 myPointsHighlight.remove(aObj);
2082 // Display new objects
2083 QList<ResultPtr> aKeysList = myPointsHighlight.keys();
2084 std::list<ResultPtr>::const_iterator aIt;
2085 for (aIt = aFreePoints.cbegin(); aIt != aFreePoints.cend(); aIt++) {
2086 if (!aKeysList.contains(*aIt)) {
2087 GeomShapePtr aShapePtr = (*aIt)->shape();
2088 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
2089 Handle(AIS_Shape) aShapePrs = new AIS_Shape(aShape);
2090 aShapePrs->SetColor(Quantity_NOC_BLUE1);
2091 aShapePrs->SetZLayer(Graphic3d_ZLayerId_Top);
2092 Handle(Prs3d_Drawer) aDrawer = aShapePrs->Attributes();
2093 if (aDrawer->HasOwnPointAspect()) {
2094 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_O_STAR);
2095 aDrawer->PointAspect()->SetColor(Quantity_NOC_BLUE1);
2096 aDrawer->PointAspect()->SetScale(2);
2099 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_O_STAR, Quantity_NOC_BLUE1, 2));
2100 aContext->Display(aShapePrs, false);
2101 aContext->Deactivate(aShapePrs);
2102 myPointsHighlight[*aIt] = aShapePrs;
2108 foreach(Handle(AIS_Shape) aPrs, myPointsHighlight.values()) {
2109 aContext->Remove(aPrs, false);
2112 myPointsHighlight.clear();
2119 void PartSet_Fitter::fitAll(Handle(V3d_View) theView)
2121 CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
2123 ModuleBase_IWorkshop* aWorkshop = mySketchMgr->module()->workshop();
2124 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
2125 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
2128 int aNumberOfSubs = aSketch->numberOfSubs();
2129 double aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
2130 for (int i = 0; i < aNumberOfSubs; i++) {
2131 FeaturePtr aFeature = aSketch->subFeature(i);
2132 if (aDisplayer->isVisible(aFeature)) {
2133 AISObjectPtr aAisPtr = aDisplayer->getAISObject(aFeature);
2134 Handle(AIS_InteractiveObject) aAisObj = aAisPtr->impl<Handle(AIS_InteractiveObject)>();
2135 if (!aAisObj->IsInfinite()) {
2137 aAisObj->BoundingBox(aBox);
2142 std::list<ResultPtr> aResults = aFeature->results();
2143 std::list<ResultPtr>::const_iterator aIt;
2145 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
2147 if (aRes->isDisplayed()) {
2148 FeaturePtr aFeature = ModelAPI_Feature::feature(aRes);
2149 if (aFeature.get()) {
2150 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
2151 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
2152 if (aSPFeature.get()) {
2154 aSPFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
2155 if (!(aSPFeature->isExternal() || isAxiliary)) {
2156 GeomShapePtr aShape = aRes->shape();
2157 aShape->computeSize(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2159 aBox.Update(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2168 if (aBndBox.IsVoid())
2171 theView->FitAll(aBndBox, 0.01);