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>
123 //#define DEBUG_DO_NOT_BY_ENTER
124 //#define DEBUG_SKETCHER_ENTITIES
125 //#define DEBUG_SKETCH_ENTITIES_ON_MOVE
126 //#define DRAGGING_DEBUG
127 //#define DEBUG_CURSOR
130 #ifdef DRAGGING_DEBUG
134 /// Fills attribute and result lists by the selected owner. In case if the attribute is found,
135 /// by the owner shape, it is put to the list. Otherwise if type of owner shape is edge,
136 /// put the function result as is to the list of results.
137 /// \param theOwner a viewer selected owner
138 /// \param theFeature a feature, where the attribute is searched
139 /// \param theSketch a current sketch
140 /// \param theSelectedAttribute an output list of attributes
141 /// \param theSelectedResults an output list of edge results
142 void getAttributesOrResults(const Handle(SelectMgr_EntityOwner)& theOwner,
143 const FeaturePtr& theFeature, const FeaturePtr& theSketch,
144 const ResultPtr& theResult,
145 std::set<AttributePtr>& theSelectedAttributes,
146 std::set<ResultPtr>& theSelectedResults,
147 TopTools_MapOfShape& theShapes)
149 Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(theOwner);
150 if (aBRepOwner.IsNull())
152 Handle(AIS_InteractiveObject) anIO = Handle(AIS_InteractiveObject)::DownCast(
153 aBRepOwner->Selectable());
154 if (aBRepOwner->HasShape()) {
155 const TopoDS_Shape& aShape = aBRepOwner->Shape();
156 theShapes.Add(aShape);
157 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
158 if (aShapeType == TopAbs_VERTEX) {
159 AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(theFeature,
161 if (aPntAttr.get() != NULL)
162 theSelectedAttributes.insert(aPntAttr);
164 else if (aShapeType == TopAbs_EDGE &&
165 theSelectedResults.find(theResult) == theSelectedResults.end()) {
166 theSelectedResults.insert(theResult);
171 PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
172 : QObject(theModule), myModule(theModule), myIsEditLaunching(false), myIsDragging(false),
173 myDragDone(false), myIsMouseOverWindow(false),
174 myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
175 myIsPopupMenuActive(false), myExternalPointsMgr(0), myNoDragMoving(false)
177 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
178 ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
180 myPreviousDrawModeEnabled = true;//aViewer->isSelectionEnabled();
182 connect(aViewer, SIGNAL(mousePress(ModuleBase_IViewWindow*, QMouseEvent*)),
183 this, SLOT(onMousePressed(ModuleBase_IViewWindow*, QMouseEvent*)));
185 connect(aViewer, SIGNAL(mouseRelease(ModuleBase_IViewWindow*, QMouseEvent*)),
186 this, SLOT(onMouseReleased(ModuleBase_IViewWindow*, QMouseEvent*)));
188 connect(aViewer, SIGNAL(mouseMove(ModuleBase_IViewWindow*, QMouseEvent*)),
189 this, SLOT(onMouseMoved(ModuleBase_IViewWindow*, QMouseEvent*)));
191 connect(aViewer, SIGNAL(mouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)),
192 this, SLOT(onMouseDoubleClick(ModuleBase_IViewWindow*, QMouseEvent*)));
194 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
195 XGUI_Workshop* aWorkshop = aConnector->workshop();
196 connect(aWorkshop, SIGNAL(applicationStarted()), this, SLOT(onApplicationStarted()));
198 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
199 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
200 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
202 mySketchPlane = new PartSet_PreviewSketchPlane();
204 registerSelectionFilter(SF_SketchCirclePointFilter, new PartSet_CirclePointFilter(anIWorkshop));
205 registerSelectionFilter(SF_SketchPlaneFilter, new ModuleBase_ShapeInPlaneFilter());
207 Events_Loop::loop()->registerListener(this, Events_Loop::eventByName(EVENT_DOF_OBJECTS));
210 PartSet_SketcherMgr::~PartSet_SketcherMgr()
212 delete mySketchPlane;
215 void PartSet_SketcherMgr::onEnterViewPort()
217 // 1. if the mouse over window, update the next flag. Do not perform update visibility of
218 // created feature because it should be done in onMouseMove(). Some widgets watch
219 // the mouse move and use the cursor position to update own values. If the presentaion is
220 // redisplayed before this update, the feature presentation jumps from reset value to current.
221 myIsMouseOverWindow = true;
223 #ifdef DEBUG_DO_NOT_BY_ENTER
227 if (canChangeCursor(getCurrentOperation())) {
228 QCursor* aCurrentCursor = QApplication::overrideCursor();
229 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
230 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
232 qDebug("onEnterViewPort() : Qt::CrossCursor");
237 if (!isNestedCreateOperation(getCurrentOperation(), activeSketch()))
240 operationMgr()->onValidateOperation();
242 // we need change displayed state of the current operation feature
243 // if the feature is presentable, e.g. distance construction. It has no results, so workshop does
244 // not accept a signal about the result created. Nothing is shown until mouse is moved out/in view
245 // port. If the isDisplayed flag is true, the presentable feature is displayed as soon as the
246 // presentation becomes valid and redisplay happens
247 //ModuleBase_Operation* aOperation = getCurrentOperation();
248 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
249 (getCurrentOperation());
251 FeaturePtr aFeature = aFOperation->feature();
252 if (aFeature.get() && aFeature->data()->isValid()) {
253 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature), false);
258 void PartSet_SketcherMgr::onLeaveViewPort()
260 myIsMouseOverViewProcessed = false;
261 myIsMouseOverWindow = false;
263 #ifdef DEBUG_DO_NOT_BY_ENTER
267 if (canChangeCursor(getCurrentOperation())) {
268 QApplication::restoreOverrideCursor();
270 qDebug("onLeaveViewPort() : None");
274 if (!isNestedCreateOperation(getCurrentOperation(), activeSketch()))
277 // the method should be performed if the popup menu is called,
278 // the reset of the current widget should not happen
279 if (myIsPopupMenuActive)
282 // it is important to validate operation here only if sketch entity create operation is active
283 // because at this operation we reacts to the mouse leave/enter view port
284 operationMgr()->onValidateOperation();
286 // 2. if the mouse IS NOT over window, reset the active widget value and hide the presentation
287 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
288 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
289 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
290 // disable the viewer update in order to avoid visualization of redisplayed feature in viewer
291 // obtained after reset value
292 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
293 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
295 anActiveWidget->reset();
297 // hides the presentation of the current operation feature
298 // the feature is to be erased here, but it is correct to call canDisplayObject because
299 // there can be additional check (e.g. editor widget in distance constraint)
300 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
301 (getCurrentOperation());
303 FeaturePtr aFeature = aFOperation->feature();
304 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
306 // we should update viewer after the presentation are hidden in the viewer
307 // otherwise the reset presentation(line) appears in the viewer(by quick move from viewer to PP)
308 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
312 //Temporary commented as we do not modify values in property panel
313 void PartSet_SketcherMgr::onBeforeValuesChangedInPropertyPanel()
315 if (!isNestedEditOperation(getCurrentOperation(), myModule->sketchMgr()->activeSketch()) ||
316 myModule->sketchReentranceMgr()->isInternalEditActive())
318 // it is necessary to save current selection in order to restore it after the values are modifed
319 storeSelection(ST_SelectAndHighlightType);
321 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
322 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
323 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
324 myPreviousUpdateViewerEnabled = aDisplayer->enableUpdateViewer(false);
327 void PartSet_SketcherMgr::onAfterValuesChangedInPropertyPanel()
329 if (!isNestedEditOperation(getCurrentOperation(), myModule->sketchMgr()->activeSketch()) ||
330 myModule->sketchReentranceMgr()->isInternalEditActive()) {
331 myModule->sketchReentranceMgr()->updateInternalEditActiveState();
334 // it is necessary to restore current selection in order to restore it after values are modified
336 myCurrentSelection.clear();
338 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
339 // viewer happens by deselect/select the modified objects. The flag should be restored after
340 // the selection processing. The update viewer should be also called.
341 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
342 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
343 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
344 aDisplayer->enableUpdateViewer(myPreviousUpdateViewerEnabled);
345 aDisplayer->updateViewer();
349 void PartSet_SketcherMgr::onMousePressed(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
351 // Clear dragging mode
352 myIsDragging = false;
354 if (myModule->sketchReentranceMgr()->processMousePressed(theWnd, theEvent))
356 //get2dPoint(theWnd, theEvent, myClickedPoint);
357 if (!(theEvent->buttons() & Qt::LeftButton))
360 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
361 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
362 //if (!aViewer->canDragByMouse())
365 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
366 (getCurrentOperation());
370 bool isEditing = aFOperation->isEditOperation();
371 bool aCanDrag = aViewer->canDragByMouse();
373 //if (!aViewer->canDragByMouse() && isEditing) {
374 // // Do not edit by dragging
379 // If the current widget is a selector, do nothing, it processes the mouse press
380 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
381 if(anActiveWidget && anActiveWidget->isViewerSelector()) {
386 // Use only for sketch operations
387 if (myCurrentSketch) {
388 if (!PartSet_Tools::sketchPlane(myCurrentSketch))
391 bool isSketcher = isSketchOperation(aFOperation);
392 bool isSketchOpe = isNestedSketchOperation(aFOperation);
394 // Avoid non-sketch operations
395 if ((!isSketchOpe) && (!isSketcher))
398 // Ignore creation sketch operation
399 if ((!isSketcher) && (!isEditing))
402 bool aHasShift = (theEvent->modifiers() & Qt::ShiftModifier);
403 storeSelection(aHasShift ? ST_SelectAndHighlightType : ST_HighlightType, myCurrentSelection);
405 if (myCurrentSelection.empty()) {
406 if (isSketchOpe && (!isSketcher))
407 // commit previous operation
408 if (!aFOperation->commit())
409 aFOperation->abort();
412 // Init flyout point for radius rotation
413 FeaturePtr aFeature = myCurrentSelection.begin().key();
415 get2dPoint(theWnd, theEvent, myCurrentPoint);
421 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
423 if (aFeature.get() != NULL) {
424 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
425 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
426 if (aSPFeature.get() &&
427 (aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID() ||
428 aSPFeature->getKind() == SketchPlugin_ConstraintAngle::ID())) {
429 DataPtr aData = aSPFeature->data();
430 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
431 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
432 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
433 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
436 } else if (isSketchOpe && isEditing) {
437 // If selected another object commit current result
438 bool aPrevLaunchingState = myIsEditLaunching;
439 /// store editing state for Edit operation in order to do not clear highlight by restart
440 /// of edit operation.
441 /// Internal edit should not be stored as editing operation as the result will be a
442 /// creation operation, where previous selection should not be used(and will be cleared)
443 myIsEditLaunching = !myModule->sketchReentranceMgr()->isInternalEditActive();
444 aFOperation->commit();
450 myPreviousDrawModeEnabled = aViewer->enableDrawMode(false);
452 myIsEditLaunching = aPrevLaunchingState;
453 if (aFeature.get() != NULL) {
454 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
455 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
456 if (aSPFeature.get() &&
457 (aSPFeature->getKind() == SketchPlugin_ConstraintRadius::ID() ||
458 aSPFeature->getKind() == SketchPlugin_ConstraintAngle::ID())) {
459 DataPtr aData = aSPFeature->data();
460 AttributePtr aAttr = aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT());
461 std::shared_ptr<GeomDataAPI_Point2D> aFPAttr =
462 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aAttr);
463 aFPAttr->setValue(myCurrentPoint.myCurX, myCurrentPoint.myCurY);
470 void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
472 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
474 aWorkshop->viewer()->enableDrawMode(myPreviousDrawModeEnabled);
476 bool aWasDragging = myIsDragging;
477 myIsDragging = false;
479 if (myModule->sketchReentranceMgr()->processMouseReleased(theWnd, theEvent)) {
482 // if mouse is pressed when it was over view and at release the mouse is out of view, do nothing
483 if (!myIsMouseOverViewProcessed) {
486 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
487 //if (!aViewer->canDragByMouse())
489 ModuleBase_OperationFeature* aOp =
490 dynamic_cast<ModuleBase_OperationFeature*>(getCurrentOperation());
492 bool aStartNoDragOperation = !aViewer->canDragByMouse() && aOp->isEditOperation();
493 if (aStartNoDragOperation || myNoDragMoving) {
494 // Process edit operation without dragging
495 if (myCurrentSelection.size() > 0)
496 myNoDragMoving = !myNoDragMoving;
498 myNoDragMoving = false;
502 restoreSelection(myCurrentSelection);
503 myCurrentSelection.clear();
507 if (isNestedSketchOperation(aOp)) {
508 // Only for sketcher operations
511 /// the previous selection is lost by mouse release in the viewer(Select method), but
512 /// it is still stored in myCurrentSelection. So, it is possible to restore selection
513 /// It is important for drag(edit with mouse) of sketch entities.
514 restoreSelection(myCurrentSelection);
515 myCurrentSelection.clear();
523 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
524 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
526 aProcessor->mouseReleased(theWnd, theEvent);
529 void PartSet_SketcherMgr::onMouseMoved(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
531 #ifdef DEBUG_SKETCH_ENTITIES_ON_MOVE
532 CompositeFeaturePtr aSketch = activeSketch();
534 std::cout << "mouse move SKETCH FEATURES [" << aSketch->numberOfSubs() << "]:" << std::endl;
536 for (int i = 0, aNbSubs = aSketch->numberOfSubs(); i < aNbSubs; i++) {
537 //std::cout << getFeatureInfo(aSketch->subFeature(i), false) << std::endl;
538 anInfo.append(ModuleBase_Tools::objectInfo(aSketch->subFeature(i)));
540 QString anInfoStr = anInfo.join("\n");
541 qDebug(QString("%1").arg(anInfo.size()).arg(anInfoStr).toStdString().c_str());
544 if (myModule->sketchReentranceMgr()->processMouseMoved(theWnd, theEvent))
547 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
548 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
549 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
551 if (isNestedCreateOperation(getCurrentOperation(), activeSketch())) {
552 #ifdef DRAGGING_DEBUG
556 // 1. perform the widget mouse move functionality and display the presentation
557 // the mouse move should be processed in the widget, if it can in order to visualize correct
558 // presentation. These widgets correct the feature attribute according to the mouse position
559 ModuleBase_ModelWidget* anActiveWidget = myModule->activeWidget();
560 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
562 aProcessor->mouseMoved(theWnd, theEvent);
563 if (!myIsMouseOverViewProcessed) {
564 myIsMouseOverViewProcessed = true;
566 // the feature is to be erased here, but it is correct to call canDisplayObject because
567 // there can be additional check (e.g. editor widget in distance constraint)
568 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
569 (getCurrentOperation());
571 FeaturePtr aFeature = aFOperation->feature();
572 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
575 aDisplayer->updateViewer();
576 #ifdef DRAGGING_DEBUG
577 cout << "Mouse move processing " << t.elapsed() << endl;
580 //myClickedPoint.clear();
582 if (myIsDragging || myNoDragMoving) {
583 // 1. the current selection is saved in the mouse press method in order to restore it after
585 // 2. the enable selection in the viewer should be temporary switched off in order to ignore
586 // mouse press signal in the viewer(it call Select for AIS context and the dragged objects are
587 // deselected). This flag should be restored in the slot, processed the mouse release signal.
588 ModuleBase_Operation* aCurrentOperation = getCurrentOperation();
589 if (!aCurrentOperation)
591 if (isSketchOperation(aCurrentOperation))
592 return; // No edit operation activated
594 #ifdef DRAGGING_DEBUG
599 Handle(V3d_View) aView = theWnd->v3dView();
600 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
602 get2dPoint(theWnd, theEvent, aMousePnt);
604 std::shared_ptr<GeomAPI_Pnt2d> anOriginalPosition = std::shared_ptr<GeomAPI_Pnt2d>(
605 new GeomAPI_Pnt2d(myCurrentPoint.myCurX, myCurrentPoint.myCurY));
606 std::shared_ptr<GeomAPI_Pnt2d> aCurrentPosition = std::shared_ptr<GeomAPI_Pnt2d>(
607 new GeomAPI_Pnt2d(aMousePnt.myCurX, aMousePnt.myCurY));
609 // 3. the flag to disable the update viewer should be set in order to avoid blinking in the
610 // viewer happens by deselect/select the modified objects. The flag should be restored after
611 // the selection processing. The update viewer should be also called.
612 bool isEnableUpdateViewer = aDisplayer->enableUpdateViewer(false);
614 static Events_ID aMoveEvent = Events_Loop::eventByName(EVENT_OBJECT_MOVED);
615 //static Events_ID aUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
616 FeatureToSelectionMap::const_iterator anIt = myCurrentSelection.begin(),
617 aLast = myCurrentSelection.end();
618 // 4. the features and attributes modification(move)
619 bool isModified = false;
620 for (; anIt != aLast; anIt++) {
621 FeaturePtr aFeature = anIt.key();
623 std::set<AttributePtr> anAttributes = anIt.value().myAttributes;
624 // Process selection by attribute: the priority to the attribute
625 if (!anAttributes.empty()) {
626 std::set<AttributePtr>::const_iterator anAttIt = anAttributes.begin(),
627 anAttLast = anAttributes.end();
628 for (; anAttIt != anAttLast; anAttIt++) {
629 AttributePtr anAttr = *anAttIt;
630 if (anAttr.get() == NULL)
632 std::string aAttrId = anAttr->id();
633 DataPtr aData = aFeature->data();
634 if (aData->isValid()) {
635 std::shared_ptr<GeomDataAPI_Point2D> aPoint =
636 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(aAttrId));
637 if (aPoint.get() != NULL) {
638 bool isImmutable = aPoint->setImmutable(true);
640 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage = std::shared_ptr
641 <ModelAPI_ObjectMovedMessage>(new ModelAPI_ObjectMovedMessage(this));
642 aMessage->setMovedAttribute(aPoint);
643 aMessage->setOriginalPosition(anOriginalPosition);
644 aMessage->setCurrentPosition(aCurrentPosition);
645 Events_Loop::loop()->send(aMessage);
648 aPoint->setImmutable(isImmutable);
654 // Process selection by feature
655 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
656 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
657 if (aSketchFeature) {
658 std::shared_ptr<ModelAPI_ObjectMovedMessage> aMessage = std::shared_ptr
659 <ModelAPI_ObjectMovedMessage>(new ModelAPI_ObjectMovedMessage(this));
660 aMessage->setMovedObject(aFeature);
661 aMessage->setOriginalPosition(anOriginalPosition);
662 aMessage->setCurrentPosition(aCurrentPosition);
663 Events_Loop::loop()->send(aMessage);
668 // the modified state of the current operation should be updated if there are features, which
671 aCurrentOperation->onValuesChanged();
672 Events_Loop::loop()->flush(aMoveEvent); // up all move events - to be processed in the solver
674 //Events_Loop::loop()->flush(aUpdateEvent); // up update events - to redisplay presentations
676 // 5. it is necessary to save current selection in order to restore it after the features moving
677 restoreSelection(myCurrentSelection);
678 // 6. restore the update viewer flag and call this update
679 aDisplayer->enableUpdateViewer(isEnableUpdateViewer);
680 aDisplayer->updateViewer();
682 #ifdef DRAGGING_DEBUG
683 cout << "Mouse move processing " << t.elapsed() << endl;
687 myCurrentPoint = aMousePnt;
691 void PartSet_SketcherMgr::onMouseDoubleClick(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
693 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
694 (getCurrentOperation());
695 if (aFOperation && aFOperation->isEditOperation()) {
696 std::string aId = aFOperation->id().toStdString();
697 if (isDistanceOperation(aFOperation))
699 // Activate dimension value editing on double click
700 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
701 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
702 // Find corresponded widget to activate value editing
703 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
704 std::string anId = aWgt->attributeID();
705 if (anId == SketchPlugin_Constraint::VALUE() ||
706 anId == SketchPlugin_ConstraintAngle::ANGLE_VALUE_ID() ||
707 anId == SketchPlugin_ConstraintDistanceAlongDir::DISTANCE_VALUE_ID()) {
708 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
710 anEditor->showPopupEditor();
718 void PartSet_SketcherMgr::onApplicationStarted()
720 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
721 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
722 XGUI_Workshop* aWorkshop = aConnector->workshop();
723 PartSet_SketcherReentrantMgr* aReentranceMgr = myModule->sketchReentranceMgr();
725 XGUI_PropertyPanel* aPropertyPanel = aWorkshop->propertyPanel();
726 if (aPropertyPanel) {
727 //connect(aPropertyPanel, SIGNAL(beforeWidgetActivated(ModuleBase_ModelWidget*)),
728 // this, SLOT(onBeforeWidgetActivated(ModuleBase_ModelWidget*)));
730 connect(aPropertyPanel, SIGNAL(noMoreWidgets(const std::string&)),
731 aReentranceMgr, SLOT(onNoMoreWidgets(const std::string&)));
732 //connect(aPropertyPanel, SIGNAL(widgetActivated(ModuleBase_ModelWidget*)),
733 // aReentranceMgr, SLOT(onWidgetActivated()));
736 XGUI_ViewerProxy* aViewerProxy = aWorkshop->viewer();
737 connect(aViewerProxy, SIGNAL(enterViewPort()), this, SLOT(onEnterViewPort()));
738 connect(aViewerProxy, SIGNAL(leaveViewPort()), this, SLOT(onLeaveViewPort()));
740 XGUI_ContextMenuMgr* aContextMenuMgr = aWorkshop->contextMenuMgr();
741 connect(aContextMenuMgr, SIGNAL(beforeContextMenu()), this, SLOT(onBeforeContextMenu()));
742 connect(aContextMenuMgr, SIGNAL(afterContextMenu()), this, SLOT(onAfterContextMenu()));
745 //void PartSet_SketcherMgr::onBeforeWidgetActivated(ModuleBase_ModelWidget* theWidget)
747 //if (!myClickedPoint.myIsInitialized)
750 //ModuleBase_Operation* aOperation = getCurrentOperation();
751 // the distance constraint feature should not use the clickedd point
752 // this is workaround in order to don't throw down the flyout point value,
753 // set by execute() method of these type of features
754 //if (isDistanceOperation(aOperation))
757 //PartSet_WidgetPoint2D* aPnt2dWgt = dynamic_cast<PartSet_WidgetPoint2D*>(theWidget);
759 // aPnt2dWgt->setPoint(myClickedPoint.myCurX, myClickedPoint.myCurY);
763 void PartSet_SketcherMgr::onBeforeContextMenu()
765 myIsPopupMenuActive = true;
768 void PartSet_SketcherMgr::onAfterContextMenu()
770 myIsPopupMenuActive = false;
773 void PartSet_SketcherMgr::get2dPoint(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent,
776 Handle(V3d_View) aView = theWnd->v3dView();
777 gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), aView);
779 PartSet_Tools::convertTo2D(aPoint, myCurrentSketch, aView, aX, anY);
780 thePoint.setValue(aX, anY);
783 void PartSet_SketcherMgr::launchEditing()
785 if (!myCurrentSelection.empty()) {
786 FeaturePtr aFeature = myCurrentSelection.begin().key();
787 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
788 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
790 if (!aSPFeature->isExternal())
791 myModule->editFeature(aSPFeature);
793 // need to edit a feature (Projection/IntersectionPoint),
794 // which produces current External feature
795 FeaturePtr aProducerFeature = PartSet_Tools::findRefsToMeFeature(aFeature,
796 SketchPlugin_Projection::ID());
797 if (!aProducerFeature.get())
798 aProducerFeature = PartSet_Tools::findRefsToMeFeature(aFeature,
799 SketchPlugin_IntersectionPoint::ID());
800 if (aProducerFeature.get())
801 myModule->editFeature(aProducerFeature);
807 bool PartSet_SketcherMgr::sketchSolverError()
809 bool anError = false;
810 CompositeFeaturePtr aSketch = activeSketch();
812 AttributeStringPtr aAttributeString = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR());
813 anError = !aAttributeString->value().empty();
818 QString PartSet_SketcherMgr::getFeatureError(const FeaturePtr& theFeature)
821 if (!theFeature.get() || !theFeature->data()->isValid())
824 CompositeFeaturePtr aSketch = activeSketch();
825 if (aSketch.get() && aSketch == theFeature) {
826 std::string aSolverError = aSketch->string(SketchPlugin_Sketch::SOLVER_ERROR())->value();
827 anError = ModuleBase_Tools::translate(aSketch->getKind(), aSolverError);
832 void PartSet_SketcherMgr::clearClickedFlags()
834 //myClickedPoint.clear();
835 myCurrentPoint.clear();
838 const QStringList& PartSet_SketcherMgr::replicationsIdList()
840 static QStringList aReplicationIds;
841 if (aReplicationIds.size() == 0) {
842 aReplicationIds << SketchPlugin_ConstraintMirror::ID().c_str();
843 aReplicationIds << SketchPlugin_MultiRotation::ID().c_str();
844 aReplicationIds << SketchPlugin_MultiTranslation::ID().c_str();
846 return aReplicationIds;
849 const QStringList& PartSet_SketcherMgr::constraintsIdList()
851 static QStringList aConstraintIds;
852 if (aConstraintIds.size() == 0) {
853 aConstraintIds << SketchPlugin_ConstraintLength::ID().c_str();
854 aConstraintIds << SketchPlugin_ConstraintDistance::ID().c_str();
855 aConstraintIds << SketchPlugin_ConstraintRigid::ID().c_str();
856 aConstraintIds << SketchPlugin_ConstraintRadius::ID().c_str();
857 aConstraintIds << SketchPlugin_ConstraintPerpendicular::ID().c_str();
858 aConstraintIds << SketchPlugin_ConstraintParallel::ID().c_str();
859 aConstraintIds << SketchPlugin_ConstraintHorizontal::ID().c_str();
860 aConstraintIds << SketchPlugin_ConstraintVertical::ID().c_str();
861 aConstraintIds << SketchPlugin_ConstraintEqual::ID().c_str();
862 aConstraintIds << SketchPlugin_ConstraintTangent::ID().c_str();
863 aConstraintIds << SketchPlugin_ConstraintCoincidence::ID().c_str();
864 aConstraintIds << SketchPlugin_ConstraintAngle::ID().c_str();
865 aConstraintIds << SketchPlugin_ConstraintCollinear::ID().c_str();
866 aConstraintIds << SketchPlugin_ConstraintMiddle::ID().c_str();
867 aConstraintIds << SketchPlugin_ConstraintMirror::ID().c_str();
868 aConstraintIds << SketchPlugin_MultiTranslation::ID().c_str();
869 aConstraintIds << SketchPlugin_MultiRotation::ID().c_str();
870 aConstraintIds << SketchPlugin_ConstraintDistanceAlongDir::ID().c_str();
871 aConstraintIds << SketchPlugin_ConstraintDistanceHorizontal::ID().c_str();
872 aConstraintIds << SketchPlugin_ConstraintDistanceVertical::ID().c_str();
874 return aConstraintIds;
877 void PartSet_SketcherMgr::sketchSelectionModes(const CompositeFeaturePtr& theSketch,
880 if (!theSketch.get() || !PartSet_Tools::sketchPlane(theSketch).get())
883 theModes.append(SketcherPrs_Tools::Sel_Dimension_Text);
884 theModes.append(SketcherPrs_Tools::Sel_Dimension_Line);
885 theModes.append(SketcherPrs_Tools::Sel_Constraint);
886 theModes.append(TopAbs_VERTEX);
887 theModes.append(TopAbs_EDGE);
890 Handle(AIS_InteractiveObject) PartSet_SketcherMgr::createPresentation(const ResultPtr& theResult)
892 Handle(AIS_InteractiveObject) aPrs;
894 FeaturePtr aFeature = ModelAPI_Feature::feature(theResult);
895 if (aFeature.get() && aFeature->getKind() == SketchPlugin_Sketch::ID()) {
896 aPrs = new PartSet_ResultSketchPrs(theResult);
901 bool PartSet_SketcherMgr::isSketchOperation(ModuleBase_Operation* theOperation)
903 return theOperation && theOperation->id().toStdString() == SketchPlugin_Sketch::ID();
906 bool PartSet_SketcherMgr::isNestedSketchOperation(ModuleBase_Operation* theOperation) const
908 bool aNestedSketch = false;
910 FeaturePtr anActiveSketch = activeSketch();
911 if (anActiveSketch.get() && theOperation) {
912 ModuleBase_Operation* aSketchOperation = operationMgr()->findOperation(
913 anActiveSketch->getKind().c_str());
914 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
916 if (aSketchOperation && aFOperation) {
917 FeaturePtr aFeature = aFOperation->feature();
918 if (aFeature.get()) {
919 QStringList aGrantedOpIds = aSketchOperation->grantedOperationIds();
920 aNestedSketch = aGrantedOpIds.contains(aFeature->getKind().c_str());
924 return aNestedSketch;
927 bool PartSet_SketcherMgr::isNestedSketchFeature(const QString& theFeatureKind) const
929 bool aNestedSketch = false;
931 FeaturePtr anActiveSketch = activeSketch();
932 if (anActiveSketch.get()) {
933 ModuleBase_Operation* aSketchOperation = operationMgr()->findOperation(
934 anActiveSketch->getKind().c_str());
935 if (aSketchOperation) {
936 QStringList aGrantedOpIds = aSketchOperation->grantedOperationIds();
937 aNestedSketch = aGrantedOpIds.contains(theFeatureKind);
940 return aNestedSketch;
943 bool PartSet_SketcherMgr::isNestedCreateOperation(ModuleBase_Operation* theOperation,
944 const CompositeFeaturePtr& theSketch) const
946 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
948 return aFOperation && !aFOperation->isEditOperation() &&
949 isNestedSketchOperation(aFOperation);
952 bool PartSet_SketcherMgr::isNestedEditOperation(ModuleBase_Operation* theOperation,
953 const CompositeFeaturePtr& theSketch) const
955 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
957 return aFOperation && aFOperation->isEditOperation() &&
958 isNestedSketchOperation(aFOperation);
961 bool PartSet_SketcherMgr::isEntity(const std::string& theId)
963 return (theId == SketchPlugin_Line::ID()) ||
964 (theId == SketchPlugin_Point::ID()) ||
965 (theId == SketchPlugin_Arc::ID()) ||
966 (theId == SketchPlugin_Circle::ID()) ||
967 (theId == SketchPlugin_Ellipse::ID()) ||
968 (theId == SketchPlugin_EllipticArc::ID());
971 bool PartSet_SketcherMgr::isExternalFeature(const FeaturePtr& theFeature)
973 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
974 std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
975 return aSPFeature.get() && aSPFeature->isExternal();
978 bool PartSet_SketcherMgr::isDistanceOperation(ModuleBase_Operation* theOperation)
980 std::string anId = theOperation ? theOperation->id().toStdString() : "";
982 return isDistanceKind(anId);
985 bool PartSet_SketcherMgr::isDistanceKind(std::string& theKind)
987 return (theKind == SketchPlugin_ConstraintLength::ID()) ||
988 (theKind == SketchPlugin_ConstraintDistance::ID()) ||
989 (theKind == SketchPlugin_ConstraintRadius::ID()) ||
990 (theKind == SketchPlugin_ConstraintAngle::ID()) ||
991 (theKind == SketchPlugin_ConstraintDistanceHorizontal::ID()) ||
992 (theKind == SketchPlugin_ConstraintDistanceVertical::ID()) ||
993 (theKind == SketchPlugin_ConstraintDistanceAlongDir::ID());
996 void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation)
998 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
999 (getCurrentOperation());
1003 SketcherPrs_Tools::setPixelRatio(ModuleBase_Tools::currentPixelRatio());
1005 myModule->onViewTransformed();
1007 // Display all sketcher sub-Objects
1008 myCurrentSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFOperation->feature());
1009 double aSizeOfView = 0;
1010 std::shared_ptr<GeomAPI_Pnt> aCentralPoint;
1011 if (aFOperation->isEditOperation() &&
1012 mySketchPlane->getDefaultSizeOfView(myCurrentSketch, aSizeOfView, aCentralPoint)) {
1013 mySketchPlane->setSizeOfView(aSizeOfView, true, aCentralPoint);
1016 mySketchPlane->createSketchPlane(myCurrentSketch, myModule->workshop());
1017 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
1019 // Hide sketcher result
1020 std::list<ResultPtr> aResults = myCurrentSketch->results();
1021 std::list<ResultPtr>::const_iterator aIt;
1022 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1023 (*aIt)->setDisplayed(false);
1025 myCurrentSketch->setDisplayed(false);
1027 // Remove invalid sketch entities
1028 std::set<FeaturePtr> anInvalidFeatures;
1029 ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
1030 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
1031 for (int i = 0; i < aNumberOfSubs; i++) {
1032 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1033 if (aFeature.get()) {
1034 if (!aFactory->validate(aFeature))
1035 anInvalidFeatures.insert(aFeature);
1038 if (!anInvalidFeatures.empty()) {
1039 std::map<FeaturePtr, std::set<FeaturePtr> > aReferences;
1040 ModelAPI_Tools::findAllReferences(anInvalidFeatures, aReferences, false);
1042 std::set<FeaturePtr>::const_iterator anIt = anInvalidFeatures.begin(),
1043 aLast = anInvalidFeatures.end();
1044 // separate features to references to parameter features and references to others
1045 QStringList anInvalidFeatureNames;
1046 for (; anIt != aLast; anIt++) {
1047 FeaturePtr aFeature = *anIt;
1049 anInvalidFeatureNames.append(aFeature->name().c_str());
1051 std::string aPrefixInfo = QString("Invalid features of the sketch will be deleted: %1.\n\n").
1052 arg(anInvalidFeatureNames.join(", ")).toStdString().c_str();
1053 std::set<FeaturePtr> aFeatureRefsToDelete;
1054 if (ModuleBase_Tools::askToDelete(anInvalidFeatures, aReferences, aConnector->desktop(),
1055 aFeatureRefsToDelete, aPrefixInfo)) {
1056 if (!aFeatureRefsToDelete.empty())
1057 anInvalidFeatures.insert(aFeatureRefsToDelete.begin(), aFeatureRefsToDelete.end());
1058 ModelAPI_Tools::removeFeatures(anInvalidFeatures, true);
1059 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
1060 // TODO: call the next method in the XGUI_OperationMgr::onOperationStarted().
1061 workshop()->errorMgr()->updateAcceptAllAction(myCurrentSketch);
1065 // update state of overconstraint listener should be done before sketch features/results
1066 // display (as the display will ask custom color from the listener)
1067 myModule->overconstraintListener()->setActive(true);
1068 // Display sketcher objects
1070 Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1071 const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
1072 aNumberOfSubs = myCurrentSketch->numberOfSubs();
1073 for (int i = 0; i < aNumberOfSubs; i++) {
1074 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1075 #ifdef DEBUG_SKETCHER_ENTITIES
1076 anInfo.append(ModuleBase_Tools::objectInfo(aFeature));
1078 std::list<ResultPtr> aResults = aFeature->results();
1079 std::list<ResultPtr>::const_iterator aIt;
1080 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1081 if ((*aIt)->isDisplayed())
1082 // Display object if it was created outside of GUI
1083 aECreator->sendUpdated((*aIt), EVENT_DISP);
1085 (*aIt)->setDisplayed(true);
1087 if (aFeature->isDisplayed())
1088 aECreator->sendUpdated(aFeature, EVENT_DISP);
1090 aFeature->setDisplayed(true);
1092 #ifdef DEBUG_SKETCHER_ENTITIES
1093 QString anInfoStr = anInfo.join(";\t");
1094 qDebug(QString("startSketch: %1, %2").arg(anInfo.size()).arg(anInfoStr).toStdString().c_str());
1097 bool aHasPlane = false;
1098 std::shared_ptr<GeomAPI_Pln> aPln;
1099 aPln = PartSet_Tools::sketchPlane(myCurrentSketch);
1100 Handle(SelectMgr_Filter) aFilter = myModule->selectionFilter(SF_SketchPlaneFilter);
1101 if (!aFilter.IsNull())
1102 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(aPln);
1104 workshop()->selectionActivate()->updateSelectionFilters();
1105 workshop()->selectionActivate()->updateSelectionModes();
1107 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1109 myExternalPointsMgr = new PartSet_ExternalPointsMgr(myModule->workshop(), myCurrentSketch);
1111 workshop()->viewer()->set2dMode(true);
1113 PartSet_Fitter* aFitter = new PartSet_Fitter(this);
1114 myModule->workshop()->viewer()->setFitter(aFitter);
1117 void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation)
1119 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myModule->workshop());
1120 PartSet_Fitter* aFitter = (PartSet_Fitter*)myModule->workshop()->viewer()->fitter();
1121 myModule->workshop()->viewer()->setFitter(0);
1124 myIsMouseOverWindow = false;
1125 myIsConstraintsShown[PartSet_Tools::Geometrical] = true;
1126 myIsConstraintsShown[PartSet_Tools::Dimensional] = true;
1127 myIsConstraintsShown[PartSet_Tools::Expressions] = false;
1129 if (myExternalPointsMgr) {
1130 delete myExternalPointsMgr;
1131 myExternalPointsMgr = 0;
1133 onShowPoints(false);
1135 DataPtr aData = myCurrentSketch->data();
1136 if (!aData->isValid()) {
1137 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1138 // The sketch was aborted
1139 myCurrentSketch = CompositeFeaturePtr();
1140 mySketchPlane->eraseSketchPlane(myModule->workshop());
1142 // Erase all sketcher objects
1143 QObjectPtrList aObjects = aDisplayer->displayedObjects();
1144 foreach (ObjectPtr aObj, aObjects) {
1145 DataPtr aObjData = aObj->data();
1146 if (!aObjData->isValid())
1147 aObj->setDisplayed(false);
1151 // Hide all sketcher sub-Objects
1152 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
1153 for (int i = 0; i < aNumberOfSubs; i++) {
1154 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1155 std::list<ResultPtr> aResults = aFeature->results();
1156 std::list<ResultPtr>::const_iterator aIt;
1157 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1158 (*aIt)->setDisplayed(false);
1160 aFeature->setDisplayed(false);
1162 // Display sketcher result
1163 std::list<ResultPtr> aResults = myCurrentSketch->results();
1164 std::list<ResultPtr>::const_iterator aIt;
1165 Events_Loop* aLoop = Events_Loop::loop();
1166 static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1168 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1170 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1171 if (!aFOperation->isDisplayedOnStart(*aIt)) {
1172 (*aIt)->setDisplayed(true);
1173 // this display event is needed because sketch already may have "displayed" state,
1174 // but not displayed while it is still active (issue 613, abort of existing sketch)
1175 ModelAPI_EventCreator::get()->sendUpdated(*aIt, aDispEvent);
1178 if (!aFOperation->isDisplayedOnStart(myCurrentSketch))
1179 myCurrentSketch->setDisplayed(true);
1181 myCurrentSketch = CompositeFeaturePtr();
1182 mySketchPlane->eraseSketchPlane(myModule->workshop());
1184 Events_Loop::loop()->flush(aDispEvent);
1186 workshop()->selectionActivate()->updateSelectionFilters();
1187 workshop()->selectionActivate()->updateSelectionModes();
1188 workshop()->viewer()->set2dMode(false);
1191 void PartSet_SketcherMgr::startNestedSketch(ModuleBase_Operation* theOperation)
1193 if (canChangeCursor(theOperation) && myIsMouseOverWindow) {
1194 QCursor* aCurrentCursor = QApplication::overrideCursor();
1195 if (!aCurrentCursor || aCurrentCursor->shape() != Qt::CrossCursor) {
1196 QApplication::setOverrideCursor(QCursor(Qt::CrossCursor));
1198 qDebug("startNestedSketch() : Qt::CrossCursor");
1204 void PartSet_SketcherMgr::stopNestedSketch(ModuleBase_Operation* theOperation)
1206 myIsMouseOverViewProcessed = true;
1207 operationMgr()->onValidateOperation();
1208 // when sketch nested operation is stopped the cursor should be restored unconditionally
1209 //if (canChangeCursor(theOperation)) {
1210 QApplication::restoreOverrideCursor();
1212 qDebug("stopNestedSketch() : None");
1215 /// improvement to deselect automatically all eventual selected objects, when
1216 // returning to the neutral point of the Sketcher
1217 bool isClearSelectionPossible = true;
1218 if (myIsEditLaunching) {
1219 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1222 FeaturePtr aFeature = aFOperation->feature();
1223 if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
1224 isClearSelectionPossible = false;
1228 if (isClearSelectionPossible)
1229 workshop()->selector()->clearSelection();
1230 if (myPointsHighlight.size())
1234 void PartSet_SketcherMgr::commitNestedSketch(ModuleBase_Operation* theOperation)
1236 if (isNestedCreateOperation(theOperation, activeSketch())) {
1237 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1240 FeaturePtr aFeature = aFOperation->feature();
1241 // it is necessary to check the the feature data validity because
1242 // some kind of features are removed by an operation commit(the macro state of a feature)
1243 if (aFeature.get() && aFeature->data()->isValid()) {
1244 visualizeFeature(aFeature, aFOperation->isEditOperation(), true);
1250 bool PartSet_SketcherMgr::sketchSelectionFilter(const ModuleBase_SelectionFilterType theFilterType)
1252 return mySelectionFilterTypes.find(theFilterType) != mySelectionFilterTypes.end();
1255 void PartSet_SketcherMgr::registerSelectionFilter(
1256 const ModuleBase_SelectionFilterType theFilterType, const Handle(SelectMgr_Filter)& theFilter)
1258 mySelectionFilterTypes.insert(theFilterType);
1259 myModule->registerSelectionFilter(theFilterType, theFilter);
1262 bool PartSet_SketcherMgr::operationActivatedByPreselection()
1264 bool isOperationStopped = false;
1265 ModuleBase_Operation* anOperation = getCurrentOperation();
1266 if(anOperation && isNestedSketchOperation(anOperation)) {
1267 // Set final definitions if they are necessary
1268 //propertyPanelDefined(aOperation);
1269 /// Commit sketcher operations automatically
1270 /// distance operation are able to show popup editor to modify the distance value
1271 /// after entering the value, the operation should be committed/aborted(by Esc key)
1272 bool aCanCommitOperation = true;
1273 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1275 if (aFOperation && PartSet_SketcherMgr::isDistanceOperation(aFOperation)) {
1276 bool aValueAccepted = setDistanceValueByPreselection(anOperation, myModule->workshop(),
1277 aCanCommitOperation);
1278 if (!aValueAccepted)
1279 return isOperationStopped;
1282 if (aCanCommitOperation)
1283 isOperationStopped = anOperation->commit();
1285 anOperation->abort();
1286 isOperationStopped = true;
1289 return isOperationStopped;
1292 bool PartSet_SketcherMgr::canUndo() const
1294 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1297 bool PartSet_SketcherMgr::canRedo() const
1299 return isNestedCreateOperation(getCurrentOperation(), activeSketch());
1302 bool PartSet_SketcherMgr::canEraseObject(const ObjectPtr& theObject) const
1304 bool aCanErase = true;
1305 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1306 if (myCurrentSketch.get()) {
1307 return !isObjectOfSketch(theObject);
1312 bool PartSet_SketcherMgr::canDisplayObject(const ObjectPtr& theObject) const
1314 bool aCanDisplay = true;
1316 bool aHasActiveSketch = activeSketch().get() != NULL;
1317 if (aHasActiveSketch) {
1318 // 1. the sketch feature should not be displayed during the sketch active operation
1319 // it is hidden by a sketch operation start and shown by a sketch stop, just the sketch
1320 // nested features can be visualized
1321 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1322 if (aFeature.get() != NULL && aFeature == activeSketch()) {
1323 aCanDisplay = false;
1325 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1326 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1327 /// some sketch entities should be never shown, e.g. projection feature
1328 if (aSketchFeature.get())
1329 aCanDisplay = aSketchFeature->canBeDisplayed();
1331 else { // there are no an active sketch
1332 // 2. sketch sub-features should not be visualized if the sketch operation is not active
1333 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1334 if (aFeature.get() != NULL) {
1335 std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
1336 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
1337 if (aSketchFeature.get()) {
1338 aCanDisplay = false;
1343 // 3. the method should not filter the objects, which are not related to the current operation.
1344 // The object is filtered just if it is a current operation feature or this feature result
1346 bool isObjectFound = false;
1347 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1348 (getCurrentOperation());
1350 FeaturePtr aFeature = aFOperation->feature();
1351 if (aFeature.get()) {
1352 std::list<ResultPtr> aResults = aFeature->results();
1353 if (theObject == aFeature)
1354 isObjectFound = true;
1356 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLast = aResults.end();
1357 for (; anIt != aLast && !isObjectFound; anIt++) {
1358 isObjectFound = *anIt == theObject;
1363 if (isObjectFound) {
1364 // 4. For created nested feature operation do not display the created feature if
1365 // the mouse curstor leaves the OCC window.
1366 // The correction cases, which ignores this condition:
1367 // a. the property panel values modification
1368 // b. the popup menu activated
1369 // c. widget editor control
1370 #ifndef DEBUG_DO_NOT_BY_ENTER
1371 if (isNestedCreateOperation(getCurrentOperation(), activeSketch())) {
1372 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1373 ModuleBase_WidgetEditor* anEditorWdg =
1374 anActiveWidget ? dynamic_cast<ModuleBase_WidgetEditor*>(anActiveWidget) : 0;
1375 // the active widget editor should not influence here. The presentation should be visible
1376 // always when this widget is active.
1377 if (!anEditorWdg && !myIsPopupMenuActive) {
1378 // during a nested create operation, the feature is redisplayed only
1379 // if the mouse over view
1380 // of there was a value modified in the property panel after the mouse left the view
1381 aCanDisplay = canDisplayCurrentCreatedFeature();
1388 // checks the sketcher constraints visibility according to active sketch check box states
1390 bool aProcessed = false;
1391 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1392 if (aFeature.get()) {
1393 bool aConstraintDisplayed = canDisplayConstraint(aFeature, PartSet_Tools::Any, aProcessed);
1395 aCanDisplay = aConstraintDisplayed;
1402 bool PartSet_SketcherMgr::canDisplayConstraint(const FeaturePtr& theFeature,
1403 const PartSet_Tools::ConstraintVisibleState& theState,
1404 bool& isProcessed) const
1406 bool aSwitchedOn = true;
1408 const QStringList& aConstrIds = constraintsIdList();
1410 std::string aKind = theFeature->getKind();
1411 if (aConstrIds.contains(QString(aKind.c_str()))) {
1412 bool isTypedConstraint = false;
1415 case PartSet_Tools::Dimensional: {
1416 bool isDistance = isDistanceKind(aKind);
1419 aSwitchedOn = myIsConstraintsShown[theState];
1423 case PartSet_Tools::Geometrical: {
1424 bool isGeometrical = !isDistanceKind(aKind);
1425 if (isGeometrical) {
1427 aSwitchedOn = myIsConstraintsShown[theState];
1431 case PartSet_Tools::Any: {
1433 bool isDistance = isDistanceKind(aKind);
1435 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Dimensional];
1437 aSwitchedOn = myIsConstraintsShown[PartSet_Tools::Geometrical];
1447 /*void PartSet_SketcherMgr::processHiddenObject(const std::list<ObjectPtr>& theObjects)
1449 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1450 (getCurrentOperation());
1451 if (aFOperation && myCurrentSketch.get()) {
1452 // find results of the current operation
1453 // these results should not be proposed to be deleted
1454 FeaturePtr anOperationFeature = aFOperation->feature();
1455 std::list<ResultPtr> anOperationResultList = anOperationFeature->results();
1456 std::set<ResultPtr> anOperationResults;
1457 std::list<ResultPtr>::const_iterator aRIt = anOperationResultList.begin(),
1458 aRLast = anOperationResultList.end();
1459 for (; aRIt != aRLast; aRIt++)
1460 anOperationResults.insert(*aRIt);
1462 std::set<FeaturePtr> anObjectsToBeDeleted;
1463 QStringList anObjectsToBeDeletedNames;
1464 std::list<ObjectPtr>::const_iterator anIt = theObjects.begin(), aLast = theObjects.end();
1465 for (; anIt != aLast; anIt++) {
1466 ObjectPtr anObject = *anIt;
1467 bool aCanErase = true;
1468 // when the sketch operation is active, results of sketch sub-feature can not be hidden
1469 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1470 // the result is found between current feature results
1471 if (anOperationResults.find(aResult) != anOperationResults.end())
1474 if (aResult.get()) {
1475 // Display sketcher objects
1476 for (int i = 0; i < myCurrentSketch->numberOfSubs() && aCanErase; i++) {
1477 FeaturePtr aFeature = myCurrentSketch->subFeature(i);
1478 std::list<ResultPtr> aResults = aFeature->results();
1479 std::list<ResultPtr>::const_iterator anIt;
1480 for (anIt = aResults.begin(); anIt != aResults.end() && aCanErase; ++anIt) {
1481 aCanErase = *anIt != aResult;
1486 FeaturePtr aFeature = ModelAPI_Feature::feature(anObject);
1487 if (aFeature.get() && anObjectsToBeDeleted.find(aFeature) == anObjectsToBeDeleted.end()) {
1488 anObjectsToBeDeleted.insert(aFeature);
1489 anObjectsToBeDeletedNames.append(aFeature->name().c_str());
1493 if (!anObjectsToBeDeleted.empty()) {
1494 QString aFeatureNames = anObjectsToBeDeletedNames.join(", ");
1495 QString aMessage = tr("The following features have incorrect presentation and \
1496 will be hidden: %1. Would you like to delete them?")
1497 .arg(aFeatureNames);
1498 int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Features hide"),
1499 aMessage, QMessageBox::Ok | QMessageBox::Cancel,
1500 QMessageBox::Cancel);
1501 if (anAnswer == QMessageBox::Ok) {
1502 QObjectPtrList anObjects;
1503 std::set<FeaturePtr>::const_iterator anIt = anObjectsToBeDeleted.begin(),
1504 aLast = anObjectsToBeDeleted.end();
1505 for (; anIt != aLast; anIt++)
1506 anObjects.append(*anIt);
1507 SessionPtr aMgr = ModelAPI_Session::get();
1508 DocumentPtr aDoc = aMgr->activeDocument();
1509 bool aIsOp = aMgr->isOperation();
1511 aMgr->startOperation();
1512 workshop()->deleteFeatures(anObjects);
1513 //static Events_ID aDeletedEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
1514 //static Events_ID aRedispEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
1515 //Events_Loop::loop()->flush(aDeletedEvent);
1516 //Events_Loop::loop()->flush(aRedispEvent);
1519 aMgr->finishOperation();
1525 bool PartSet_SketcherMgr::canDisplayCurrentCreatedFeature() const
1527 bool aCanDisplay = myIsMouseOverWindow;
1529 ModuleBase_ModelWidget* anActiveWidget = getActiveWidget();
1531 aCanDisplay = anActiveWidget->getValueState() == ModuleBase_ModelWidget::Stored;
1536 bool PartSet_SketcherMgr::canChangeCursor(ModuleBase_Operation* theOperation) const
1538 return isNestedCreateOperation(theOperation, activeSketch()) ||
1539 myModule->sketchReentranceMgr()->isInternalEditActive();
1542 const QMap<PartSet_Tools::ConstraintVisibleState, bool>& PartSet_SketcherMgr::showConstraintStates()
1544 return myIsConstraintsShown;
1547 bool PartSet_SketcherMgr::isObjectOfSketch(const ObjectPtr& theObject) const
1549 bool isFoundObject = false;
1551 FeaturePtr anObjectFeature = ModelAPI_Feature::feature(theObject);
1552 if (anObjectFeature.get()) {
1553 int aSize = myCurrentSketch->numberOfSubs();
1554 for (int i = 0; i < aSize && !isFoundObject; i++) {
1555 FeaturePtr aCurrentFeature = myCurrentSketch->subFeature(i);
1556 isFoundObject = myCurrentSketch->subFeature(i) == anObjectFeature;
1559 return isFoundObject;
1562 void PartSet_SketcherMgr::onPlaneSelected(const std::shared_ptr<GeomAPI_Pln>& thePlane)
1564 Handle(SelectMgr_Filter) aFilter = myModule->selectionFilter(SF_SketchPlaneFilter);
1565 if (!aFilter.IsNull())
1566 Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(thePlane);
1568 workshop()->selectionActivate()->updateSelectionModes();
1571 bool PartSet_SketcherMgr::setDistanceValueByPreselection(ModuleBase_Operation* theOperation,
1572 ModuleBase_IWorkshop* theWorkshop,
1573 bool& theCanCommitOperation)
1575 bool isValueAccepted = false;
1576 theCanCommitOperation = false;
1578 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1580 FeaturePtr aFeature = aFOperation->feature();
1581 // editor is shown only if all attribute references are filled by preseletion
1582 bool anAllRefAttrInitialized = true;
1584 std::list<AttributePtr> aRefAttrs = aFeature->data()->attributes(
1585 ModelAPI_AttributeRefAttr::typeId());
1586 std::list<AttributePtr>::const_iterator anIt = aRefAttrs.begin(), aLast = aRefAttrs.end();
1587 for (; anIt != aLast && anAllRefAttrInitialized; anIt++) {
1588 anAllRefAttrInitialized = (*anIt)->isInitialized();
1590 if (anAllRefAttrInitialized) {
1591 // Activate dimension value editing on double click
1592 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
1593 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
1594 // Find corresponded widget to activate value editing
1595 foreach (ModuleBase_ModelWidget* aWgt, aWidgets) {
1596 if (aWgt->attributeID() == "ConstraintValue") {
1597 // the featue should be displayed in order to find the AIS text position,
1598 // the place where the editor will be shown
1599 aFeature->setDisplayed(true);
1600 /// the execute is necessary to perform in the feature compute for flyout position
1601 aFeature->execute();
1603 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED));
1604 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1606 PartSet_WidgetEditor* anEditor = dynamic_cast<PartSet_WidgetEditor*>(aWgt);
1608 int aX = 0, anY = 0;
1610 XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(theWorkshop);
1611 XGUI_Displayer* aDisplayer = aWorkshop->displayer();
1612 AISObjectPtr anAIS = aDisplayer->getAISObject(aFeature);
1613 Handle(AIS_InteractiveObject) anAISIO;
1614 if (anAIS.get() != NULL) {
1615 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1617 if (anAIS.get() != NULL) {
1618 Handle(AIS_InteractiveObject) anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
1620 if (!anAISIO.IsNull()) {
1621 Handle(AIS_Dimension) aDim = Handle(AIS_Dimension)::DownCast(anAISIO);
1622 if (!aDim.IsNull()) {
1623 gp_Pnt aPosition = aDim->GetTextPosition();
1625 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
1626 Handle(V3d_View) aView = aViewer->activeView();
1628 aView->Convert(aPosition.X(), aPosition.Y(), aPosition.Z(), aCX, aCY);
1630 QWidget* aViewPort = aViewer->activeViewPort();
1631 QPoint aGlPoint = aViewPort->mapToGlobal(QPoint(aCX, aCY));
1636 anEditor->setCursorPosition(aX, anY);
1637 isValueAccepted = anEditor->showPopupEditor(false);
1638 theCanCommitOperation = true;
1644 return isValueAccepted;
1647 void PartSet_SketcherMgr::getSelectionOwners(const FeaturePtr& theFeature,
1648 const FeaturePtr& theSketch,
1649 ModuleBase_IWorkshop* theWorkshop,
1650 const FeatureToSelectionMap& theSelection,
1651 SelectMgr_IndexedMapOfOwner& theOwnersToSelect)
1653 if (theFeature.get() == NULL)
1656 FeatureToSelectionMap::const_iterator anIt = theSelection.find(theFeature);
1657 SelectionInfo anInfo = anIt.value();
1658 std::set<AttributePtr> aSelectedAttributes = anInfo.myAttributes;
1659 std::set<ResultPtr> aSelectedResults = anInfo.myResults;
1661 ModuleBase_IViewer* aViewer = theWorkshop->viewer();
1663 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(theWorkshop);
1664 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
1666 // 1. found the feature's owners. Check the AIS objects of the constructions
1667 AISObjectPtr aAISObj = aDisplayer->getAISObject(theFeature);
1668 if (aAISObj.get() != NULL && aSelectedAttributes.empty() && aSelectedResults.empty()) {
1669 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1671 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1672 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1673 for (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
1674 Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
1675 if (!anOwner.IsNull())
1676 theOwnersToSelect.Add(anOwner);
1680 // 2. found the feature results's owners
1681 std::list<ResultPtr> aResults = theFeature->results();
1682 std::list<ResultPtr>::const_iterator aIt;
1684 bool isSameShape = false;
1685 if (aResults.size() > 0) {
1686 ResultPtr aFirstResult = theFeature->firstResult();
1687 if (aFirstResult.get() && aFirstResult->shape().get()) {
1688 TopoDS_Shape aFirstShape = aFirstResult->shape()->impl<TopoDS_Shape>();
1689 isSameShape = aFirstShape.IsEqual(anInfo.myFirstResultShape);
1692 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1693 ResultPtr aResult = *aIt;
1694 AISObjectPtr aAISObj = aDisplayer->getAISObject(aResult);
1695 if (aAISObj.get() == NULL)
1697 Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
1699 SelectMgr_IndexedMapOfOwner aSelectedOwners;
1700 aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
1701 bool aFoundLocalShape = false;
1702 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1703 Handle(StdSelect_BRepOwner) anOwner =
1704 Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1705 if ( anOwner.IsNull() || !anOwner->HasShape() || theOwnersToSelect.FindIndex(anOwner))
1707 const TopoDS_Shape& aShape = anOwner->Shape();
1708 TopAbs_ShapeEnum aShapeType = aShape.ShapeType();
1709 if (aShapeType == TopAbs_VERTEX) {
1710 AttributePtr aPntAttr =
1711 PartSet_Tools::findAttributeBy2dPoint(theFeature, aShape, theSketch);
1712 if (aPntAttr.get() != NULL &&
1713 aSelectedAttributes.find(aPntAttr) != aSelectedAttributes.end())
1714 theOwnersToSelect.Add(anOwner);
1715 else if (isSameShape && anInfo.myLocalSelectedShapes.Contains(aShape)) {
1716 theOwnersToSelect.Add(anOwner);
1719 else if (aShapeType == TopAbs_EDGE) {
1720 if (isSameShape && anInfo.myLocalSelectedShapes.Contains(aShape)) {
1721 // try to restore local selection on Shape result
1722 // we can do this only if the shape was not changed
1723 theOwnersToSelect.Add(anOwner);
1724 aFoundLocalShape = true;
1729 if (!aFoundLocalShape) {
1730 // result owners are put in the list of selection only if local selected shapes were not
1732 if (aSelectedResults.find(aResult) != aSelectedResults.end()) {
1733 for ( Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++ ) {
1734 Handle(StdSelect_BRepOwner) anOwner =
1735 Handle(StdSelect_BRepOwner)::DownCast(aSelectedOwners(i));
1736 if ( anOwner.IsNull() || !anOwner->HasShape() || theOwnersToSelect.FindIndex(anOwner))
1738 // select whole result
1739 theOwnersToSelect.Add(anOwner);
1746 void PartSet_SketcherMgr::connectToPropertyPanel(ModuleBase_ModelWidget* theWidget,
1747 const bool isToConnect)
1749 //Temporary commented as we do not modify values in property panel
1751 //connect(theWidget, SIGNAL(beforeValuesChanged()),
1752 // this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1753 //connect(theWidget, SIGNAL(afterValuesChanged()),
1754 // this, SLOT(onAfterValuesChangedInPropertyPanel()));
1755 connect(theWidget, SIGNAL(afterValuesChanged()),
1756 myModule->sketchReentranceMgr(), SLOT(onAfterValuesChangedInPropertyPanel()));
1759 //disconnect(theWidget, SIGNAL(beforeValuesChanged()),
1760 // this, SLOT(onBeforeValuesChangedInPropertyPanel()));
1761 //disconnect(theWidget, SIGNAL(afterValuesChanged()),
1762 // this, SLOT(onAfterValuesChangedInPropertyPanel()));
1763 disconnect(theWidget, SIGNAL(afterValuesChanged()),
1764 myModule->sketchReentranceMgr(), SLOT(onAfterValuesChangedInPropertyPanel()));
1768 void PartSet_SketcherMgr::widgetStateChanged(int thePreviousState)
1770 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1771 (getCurrentOperation());
1773 if (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1774 isNestedSketchOperation(aFOperation) &&
1775 thePreviousState == ModuleBase_ModelWidget::ModifiedInPP) {
1776 FeaturePtr aFeature = aFOperation->feature();
1777 visualizeFeature(aFeature, aFOperation->isEditOperation(), canDisplayObject(aFeature));
1782 void PartSet_SketcherMgr::customizePresentation(const ObjectPtr& theObject)
1784 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
1785 (getCurrentOperation());
1786 if (aFOperation && (PartSet_SketcherMgr::isSketchOperation(aFOperation) ||
1787 isNestedSketchOperation(aFOperation)))
1788 SketcherPrs_Tools::sendExpressionShownEvent(myIsConstraintsShown[PartSet_Tools::Expressions]);
1790 // update entities selection priorities
1791 FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
1792 if (aFeature.get() && PartSet_SketcherMgr::isEntity(aFeature->getKind())) {
1793 // update priority for feature
1794 updateSelectionPriority(aFeature, aFeature);
1795 // update priority for results of the feature
1796 std::list<ResultPtr> aResults = aFeature->results();
1797 std::list<ResultPtr>::const_iterator anIt = aResults.begin(), aLastIt = aResults.end();
1798 for (; anIt != aLastIt; anIt++)
1799 updateSelectionPriority(*anIt, aFeature);
1803 ModuleBase_Operation* PartSet_SketcherMgr::getCurrentOperation() const
1805 return myModule->workshop()->currentOperation();
1808 //**************************************************************
1809 ModuleBase_ModelWidget* PartSet_SketcherMgr::getActiveWidget() const
1811 ModuleBase_ModelWidget* aWidget = 0;
1812 ModuleBase_Operation* anOperation = getCurrentOperation();
1814 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
1816 aWidget = aPanel->activeWidget();
1821 void PartSet_SketcherMgr::visualizeFeature(const FeaturePtr& theFeature,
1822 const bool isEditOperation,
1823 const bool isToDisplay,
1824 const bool isFlushRedisplay)
1826 #ifdef DEBUG_DO_NOT_BY_ENTER
1830 if (isEditOperation || !theFeature.get())
1833 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1834 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1836 // 1. change visibility of the object itself, here the presentable object is processed,
1837 // e.g. constraints features
1838 //FeaturePtr aFeature = aFOperation->feature();
1839 std::list<ResultPtr> aResults = theFeature->results();
1841 theFeature->setDisplayed(true);
1843 theFeature->setDisplayed(false);
1845 // change visibility of the object results, e.g. non-constraint features
1846 std::list<ResultPtr>::const_iterator aIt;
1847 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1849 (*aIt)->setDisplayed(true);
1852 (*aIt)->setDisplayed(false);
1855 if (isFlushRedisplay)
1856 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1859 void PartSet_SketcherMgr::storeSelection(const SelectionType theType,
1860 PartSet_SketcherMgr::FeatureToSelectionMap& theCurrentSelection)
1862 if (!myCurrentSketch.get())
1865 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1866 ModuleBase_ISelection* aSelect = aWorkshop->selection();
1867 QList<ModuleBase_ViewerPrsPtr> aStoredPrs;
1869 if (theType == ST_HighlightType || theType == ST_SelectAndHighlightType)
1870 aStoredPrs = aSelect->getHighlighted();
1872 QList<FeaturePtr> aFeatureList;
1873 if (theType == ST_SelectAndHighlightType || theType == ST_SelectType) {
1874 QList<ModuleBase_ViewerPrsPtr> aSelected = aSelect->getSelected(
1875 ModuleBase_ISelection::AllControls);
1876 aStoredPrs.append(aSelected);
1879 // 1. it is necessary to save current selection in order to restore it after the features moving
1880 theCurrentSelection.clear();
1882 QList<ModuleBase_ViewerPrsPtr>::const_iterator anIt = aStoredPrs.begin(),
1883 aLast = aStoredPrs.end();
1885 CompositeFeaturePtr aSketch = activeSketch();
1886 for (; anIt != aLast; anIt++) {
1887 ModuleBase_ViewerPrsPtr aPrs = *anIt;
1888 ObjectPtr anObject = aPrs->object();
1889 if (!anObject.get())
1892 ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
1893 FeaturePtr aFeature;
1895 aFeature = ModelAPI_Feature::feature(aResult);
1897 aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anObject);
1899 if (!aFeature.get())
1902 std::set<AttributePtr> aSelectedAttributes;
1903 std::set<ResultPtr> aSelectedResults;
1904 SelectionInfo anInfo;
1905 if (theCurrentSelection.find(aFeature) != theCurrentSelection.end())
1906 anInfo = theCurrentSelection.find(aFeature).value();
1908 TopoDS_Shape aFirstShape;
1909 ResultPtr aFirstResult = aFeature->firstResult();
1910 if (aFirstResult.get() && aFirstResult->shape().get())
1911 aFirstShape = aFirstResult->shape()->impl<TopoDS_Shape>();
1912 anInfo.myFirstResultShape = aFirstShape;
1913 Handle(SelectMgr_EntityOwner) anOwner = aPrs->owner();
1914 if (aResult.get()) {
1915 getAttributesOrResults(anOwner, aFeature, aSketch, aResult,
1916 anInfo.myAttributes, anInfo.myResults, anInfo.myLocalSelectedShapes);
1919 std::list<ResultPtr> aResults = aFeature->results();
1920 std::list<ResultPtr>::const_iterator aIt;
1921 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
1922 ResultPtr aResult = *aIt;
1923 getAttributesOrResults(anOwner, aFeature, aSketch, aResult,
1924 anInfo.myAttributes, anInfo.myResults, anInfo.myLocalSelectedShapes);
1927 theCurrentSelection[aFeature] = anInfo;
1929 //qDebug(QString(" storeSelection: %1").arg(theCurrentSelection.size()).toStdString().c_str());
1932 void PartSet_SketcherMgr::restoreSelection(
1933 PartSet_SketcherMgr::FeatureToSelectionMap& theCurrentSelection)
1935 if (!myCurrentSketch.get())
1938 //qDebug(QString("restoreSelection: %1").arg(theCurrentSelection.size()).toStdString().c_str());
1939 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1940 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1941 FeatureToSelectionMap::const_iterator aSIt = theCurrentSelection.begin(),
1942 aSLast = theCurrentSelection.end();
1943 SelectMgr_IndexedMapOfOwner anOwnersToSelect;
1944 anOwnersToSelect.Clear();
1945 for (; aSIt != aSLast; aSIt++) {
1946 getSelectionOwners(aSIt.key(), myCurrentSketch, aWorkshop, theCurrentSelection,
1949 aConnector->workshop()->selector()->setSelectedOwners(anOwnersToSelect, false);
1952 void PartSet_SketcherMgr::onShowConstraintsToggle(int theType, bool theState)
1954 PartSet_Tools::ConstraintVisibleState aType = (PartSet_Tools::ConstraintVisibleState)theType;
1956 updateBySketchParameters(aType, theState);
1959 void PartSet_SketcherMgr::updateBySketchParameters(
1960 const PartSet_Tools::ConstraintVisibleState& theType,
1963 if (myCurrentSketch.get() == NULL)
1966 bool aPrevState = myIsConstraintsShown[theType];
1967 myIsConstraintsShown[theType] = theState;
1970 case PartSet_Tools::Geometrical:
1971 case PartSet_Tools::Dimensional: {
1972 if (aPrevState != theState) {
1973 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
1974 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
1975 int aNumberOfSubs = myCurrentSketch->numberOfSubs();
1976 for (int i = 0; i < aNumberOfSubs; i++) {
1977 FeaturePtr aSubFeature = myCurrentSketch->subFeature(i);
1978 bool aProcessed = false;
1979 bool aConstraintDisplayed = canDisplayConstraint(aSubFeature, theType, aProcessed);
1981 aSubFeature->setDisplayed(aConstraintDisplayed);
1983 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
1987 case PartSet_Tools::Expressions: {
1988 if (aPrevState != theState) {
1989 /// call all sketch features redisplay, the expression state will be corrected in customize
1990 /// of distance presentation
1991 Events_ID anEventId = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
1992 PartSet_Tools::sendSubFeaturesEvent(myCurrentSketch, anEventId);
1999 void PartSet_SketcherMgr::updateSelectionPriority(ObjectPtr theObject,
2000 FeaturePtr theFeature)
2002 if (!theObject.get() || !theFeature.get())
2005 AISObjectPtr anAIS = workshop()->displayer()->getAISObject(theObject);
2006 Handle(AIS_InteractiveObject) anAISIO;
2007 if (anAIS.get() != NULL) {
2008 anAISIO = anAIS->impl<Handle(AIS_InteractiveObject)>();
2011 if (!anAISIO.IsNull()) { // the presentation for the object is visualized
2012 int anAdditionalPriority = 0;
2014 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
2015 std::dynamic_pointer_cast<SketchPlugin_Feature>(theFeature);
2016 if (aSPFeature.get() != NULL) {
2018 // 2. Simple segments
2019 // 3. External objects (violet color)
2020 // 4. Auxiliary segments (dotted)
2021 // StdSelect_BRepSelectionTool::Load uses priority calculating:
2022 // Standard_Integer aPriority =
2023 // (thePriority == -1) ? GetStandardPriority (theShape, theType) : thePriority;
2024 // Priority of Vertex is 8, edge(segment) is 7.
2025 // It might be not corrected as provides the condition above.
2026 bool isExternal = aSPFeature->isExternal();
2027 bool isAuxiliary = PartSet_Tools::isAuxiliarySketchEntity(aSPFeature);
2029 if (!isExternal && !isAuxiliary)
2030 anAdditionalPriority = 30;
2033 anAdditionalPriority = 20;
2034 // auxiliary feature
2036 anAdditionalPriority = 10; /// auxiliary objects should have less priority that
2037 // edges/vertices of local selection on not-sketch objects
2039 Handle(ModuleBase_ResultPrs) aResult = Handle(ModuleBase_ResultPrs)::DownCast(anAISIO);
2040 if (!aResult.IsNull()) {
2041 aResult->setAdditionalSelectionPriority(anAdditionalPriority);
2047 XGUI_Workshop* PartSet_SketcherMgr::workshop() const
2049 ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
2050 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(anIWorkshop);
2051 return aConnector->workshop();
2054 XGUI_OperationMgr* PartSet_SketcherMgr::operationMgr() const
2056 return workshop()->operationMgr();
2059 void PartSet_SketcherMgr::onShowPoints(bool toShow)
2061 if (!myCurrentSketch.get())
2063 ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
2064 ModuleBase_IViewer* aViewer = aWorkshop->viewer();
2065 Handle(AIS_InteractiveContext) aContext = aViewer->AISContext();
2067 bool aToUpdate = false;
2069 std::list<ResultPtr> aFreePoints = SketcherPrs_Tools::getFreePoints(myCurrentSketch);
2071 // Delete obsolete presentations
2072 std::list<ResultPtr> aDelList;
2073 foreach(ResultPtr aObj, myPointsHighlight.keys()) {
2074 bool aFound = (std::find(aFreePoints.begin(), aFreePoints.end(), aObj) != aFreePoints.end());
2076 aDelList.push_back(aObj);
2078 foreach(ResultPtr aObj, aDelList) {
2079 aContext->Remove(myPointsHighlight[aObj], false);
2081 myPointsHighlight.remove(aObj);
2084 // Display new objects
2085 QList<ResultPtr> aKeysList = myPointsHighlight.keys();
2086 std::list<ResultPtr>::const_iterator aIt;
2087 for (aIt = aFreePoints.cbegin(); aIt != aFreePoints.cend(); aIt++) {
2088 if (!aKeysList.contains(*aIt)) {
2089 GeomShapePtr aShapePtr = (*aIt)->shape();
2090 TopoDS_Shape aShape = aShapePtr->impl<TopoDS_Shape>();
2091 Handle(AIS_Shape) aShapePrs = new AIS_Shape(aShape);
2092 aShapePrs->SetColor(Quantity_NOC_BLUE1);
2093 aShapePrs->SetZLayer(Graphic3d_ZLayerId_Top);
2094 Handle(Prs3d_Drawer) aDrawer = aShapePrs->Attributes();
2095 if (aDrawer->HasOwnPointAspect()) {
2096 aDrawer->PointAspect()->SetTypeOfMarker(Aspect_TOM_O_STAR);
2097 aDrawer->PointAspect()->SetColor(Quantity_NOC_BLUE1);
2098 aDrawer->PointAspect()->SetScale(2);
2101 aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_O_STAR, Quantity_NOC_BLUE1, 2));
2102 aContext->Display(aShapePrs, false);
2103 aContext->Deactivate(aShapePrs);
2104 myPointsHighlight[*aIt] = aShapePrs;
2110 foreach(Handle(AIS_Shape) aPrs, myPointsHighlight.values()) {
2111 aContext->Remove(aPrs, false);
2114 myPointsHighlight.clear();
2120 void PartSet_SketcherMgr::processEvent(const std::shared_ptr<Events_Message>& theMessage)
2122 if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_DOF_OBJECTS)) {
2123 std::shared_ptr<ModelAPI_ObjectUpdatedMessage> anUpdateMsg =
2124 std::dynamic_pointer_cast<ModelAPI_ObjectUpdatedMessage>(theMessage);
2125 std::set<ObjectPtr> aObjects = anUpdateMsg->objects();
2126 std::set<ObjectPtr>::const_iterator aIt;
2127 QList<ModuleBase_ViewerPrsPtr> aPrsList;
2128 for (aIt = aObjects.cbegin(); aIt != aObjects.cend(); aIt++) {
2129 FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*aIt);
2130 if (aFeature.get()) {
2131 std::list<ResultPtr> aRes = aFeature->results();
2132 std::list<ResultPtr>::const_iterator aIt;
2133 for (aIt = aRes.cbegin(); aIt != aRes.cend(); ++aIt) {
2134 ModuleBase_ViewerPrsPtr aPrsPtr(new ModuleBase_ViewerPrs(*aIt));
2135 aPrsList.append(aPrsPtr);
2139 if (aPrsList.size() > 0) {
2140 myModule->workshop()->setSelected(aPrsList);
2145 void PartSet_Fitter::fitAll(Handle(V3d_View) theView)
2147 CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
2149 ModuleBase_IWorkshop* aWorkshop = mySketchMgr->module()->workshop();
2150 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(aWorkshop);
2151 XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
2154 int aNumberOfSubs = aSketch->numberOfSubs();
2155 double aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
2156 for (int i = 0; i < aNumberOfSubs; i++) {
2157 FeaturePtr aFeature = aSketch->subFeature(i);
2158 if (aDisplayer->isVisible(aFeature)) {
2159 AISObjectPtr aAisPtr = aDisplayer->getAISObject(aFeature);
2160 Handle(AIS_InteractiveObject) aAisObj = aAisPtr->impl<Handle(AIS_InteractiveObject)>();
2161 if (!aAisObj->IsInfinite()) {
2163 aAisObj->BoundingBox(aBox);
2168 std::list<ResultPtr> aResults = aFeature->results();
2169 std::list<ResultPtr>::const_iterator aIt;
2171 for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) {
2173 if (aRes->isDisplayed()) {
2174 FeaturePtr aFeature = ModelAPI_Feature::feature(aRes);
2175 if (aFeature.get()) {
2176 std::shared_ptr<SketchPlugin_Feature> aSPFeature =
2177 std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
2178 if (aSPFeature.get()) {
2180 aSPFeature->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value();
2181 if (!(aSPFeature->isExternal() || isAxiliary)) {
2182 GeomShapePtr aShape = aRes->shape();
2183 aShape->computeSize(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2185 aBox.Update(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
2194 if (aBndBox.IsVoid())
2197 theView->FitAll(aBndBox, 0.01);