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_SketcherReentrantMgr.h"
21 #include "PartSet_ExternalObjectsMgr.h"
22 #include "PartSet_Module.h"
23 #include "PartSet_SketcherMgr.h"
24 #include "PartSet_WidgetPoint2d.h"
26 #include "ModelAPI_Session.h"
27 #include "ModelAPI_AttributeString.h"
28 #include "ModelAPI_AttributeRefAttr.h"
29 #include "ModelAPI_AttributeReference.h"
30 #include "ModelAPI_EventReentrantMessage.h"
32 #include "GeomDataAPI_Point2D.h"
34 #include "GeomAPI_Lin2d.h"
35 #include "GeomAPI_Dir2d.h"
37 #include <ModuleBase_IPropertyPanel.h>
38 #include <ModuleBase_ISelectionActivate.h>
39 #include <ModuleBase_OperationFeature.h>
40 #include <ModuleBase_ModelWidget.h>
41 #include <ModuleBase_ViewerPrs.h>
42 #include <ModuleBase_WidgetSelector.h>
43 #include <ModuleBase_PageWidget.h>
44 #include <ModuleBase_PageBase.h>
45 #include <ModuleBase_WidgetFactory.h>
46 #include <ModuleBase_OperationDescription.h>
47 #include "ModuleBase_ToolBox.h"
48 #include "ModuleBase_ISelection.h"
50 #include <SketchPlugin_Feature.h>
51 #include <SketchPlugin_Line.h>
52 #include <SketchPlugin_MacroArc.h>
53 #include <SketchPlugin_MacroCircle.h>
54 #include <SketchPlugin_Point.h>
55 #include <SketchPlugin_Trim.h>
56 #include <SketchPlugin_Split.h>
57 #include <SketchPlugin_ConstraintHorizontal.h>
58 #include <SketchPlugin_ConstraintVertical.h>
60 #include <XGUI_Workshop.h>
61 #include <XGUI_ModuleConnector.h>
62 #include <XGUI_OperationMgr.h>
63 #include <XGUI_PropertyPanel.h>
64 #include <XGUI_ErrorMgr.h>
65 #include <XGUI_SelectionMgr.h>
67 #include <QToolButton>
69 //#define DEBUG_RESTART
71 PartSet_SketcherReentrantMgr::PartSet_SketcherReentrantMgr(ModuleBase_IWorkshop* theWorkshop)
72 : QObject(theWorkshop),
73 myWorkshop(theWorkshop),
74 myRestartingMode(RM_None),
75 myIsFlagsBlocked(false),
76 myIsInternalEditOperation(false),
77 myNoMoreWidgetsAttribute(""),
78 myIsAutoConstraints(true)
82 PartSet_SketcherReentrantMgr::~PartSet_SketcherReentrantMgr()
86 bool PartSet_SketcherReentrantMgr::isInternalEditActive() const
88 return myIsInternalEditOperation;
91 void PartSet_SketcherReentrantMgr::updateInternalEditActiveState()
93 if (myIsInternalEditOperation) {
94 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
95 (myWorkshop->currentOperation());
97 FeaturePtr aFeature = aFOperation->feature();
98 QString anError = myWorkshop->module()->getFeatureError(aFeature);
99 // stop started internal edit operation as soon as the operation becomes invalid
100 // it is especially important for the sketch tangent arc feature
101 if (!anError.isEmpty()) {
102 aFOperation->setEditOperation(false);
103 //workshop()->operationMgr()->updateApplyOfOperations();
104 myIsInternalEditOperation = false;
105 updateAcceptAllAction();
111 bool PartSet_SketcherReentrantMgr::operationCommitted(ModuleBase_Operation* theOperation)
113 bool aProcessed = false;
117 aProcessed = myIsInternalEditOperation;
123 void PartSet_SketcherReentrantMgr::operationStarted(ModuleBase_Operation* theOperation)
128 //if (myPreviousFeature.get() && myRestartingMode == RM_LastFeatureUsed) {
129 //ModuleBase_OperationFeature* aCurrentOperation = dynamic_cast<ModuleBase_OperationFeature*>(
130 // myWorkshop->currentOperation());
131 //CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
132 //if (myPreviousFeature.get() && myPreviousFeature->data()->isValid()) // it is not removed
133 //copyReetntrantAttributes(myPreviousFeature, aCurrentOperation->feature(), aSketch);
138 void PartSet_SketcherReentrantMgr::operationAborted(ModuleBase_Operation* theOperation)
146 bool PartSet_SketcherReentrantMgr::processMouseMoved(ModuleBase_IViewWindow* theWnd,
147 QMouseEvent* theEvent)
149 bool aProcessed = false;
153 if (myIsInternalEditOperation) {
154 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
155 (myWorkshop->currentOperation());
156 FeaturePtr aLastFeature = myRestartingMode == RM_LastFeatureUsed ? aFOperation->feature()
159 ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget();
160 ModuleBase_IPropertyPanel* aPanel = myWorkshop->currentOperation()->propertyPanel();
162 FeaturePtr aCurrentFeature = aFOperation->feature();
163 bool isLineFeature = false, isReentrantArcFeature = false;
164 std::string anAttributeOnStart;
165 if (aCurrentFeature->getKind() == SketchPlugin_Line::ID()) {
166 anAttributeOnStart = SketchPlugin_Line::START_ID();
167 isLineFeature = anActiveWidget->attributeID() == anAttributeOnStart;
169 else if (isTangentArc(aFOperation, module()->sketchMgr()->activeSketch())) {
170 isReentrantArcFeature = true;
172 bool aCanBeActivatedByMove = isLineFeature || isReentrantArcFeature;
173 if (aCanBeActivatedByMove) {
174 /// before restarting of operation we need to clear selection, as it may take part in
175 /// new feature creation, e.g. tangent arc. But it is not necessary as it was processed
176 /// by mouse release when the operation was restarted.
177 workshop()->selector()->clearSelection();
179 myPreviousFeature = aFOperation->feature();
180 if (myIsAutoConstraints)
181 addConstraints(myPreviousFeature);
183 myPreviousFeature = FeaturePtr();
185 anActiveWidget = module()->activeWidget();
187 if (anActiveWidget && anActiveWidget->attributeID() == anAttributeOnStart) {
188 // it was not deactivated by preselection processing
189 aPanel->activateNextWidget(anActiveWidget);
192 // processing mouse move in active widget of restarted operation
193 ModuleBase_ModelWidget* anActiveWidget = module()->activeWidget();
194 PartSet_MouseProcessor* aProcessor = dynamic_cast<PartSet_MouseProcessor*>(anActiveWidget);
196 aProcessor->mouseMoved(theWnd, theEvent);
203 bool PartSet_SketcherReentrantMgr::processMousePressed(ModuleBase_IViewWindow* /* theWnd*/,
204 QMouseEvent* /* theEvent*/)
206 return isActiveMgr() && myIsInternalEditOperation;
209 bool PartSet_SketcherReentrantMgr::processMouseReleased(ModuleBase_IViewWindow* theWindow,
210 QMouseEvent* theEvent)
212 bool aProcessed = false;
216 if (myIsInternalEditOperation) {
217 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
218 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
220 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
221 if (!anActiveWidget || !anActiveWidget->isViewerSelector()) {
223 // block of viewer update
224 // we need to block update content of the viewer because of Sketch Point feature
225 // in activate() the value of the point is initialized and it can be displayed
226 // but the default value is [0, 0]. So, we block update viewer contentent until
227 // onMouseRelease happens, which correct the point position
228 ModuleBase_Tools::blockUpdateViewer(true);
230 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
231 (myWorkshop->currentOperation());
232 myPreviousFeature = aFOperation->feature();
234 /// selection should be obtained from workshop before ask if the operation can be started as
235 /// the canStartOperation method performs commit/abort of previous operation.
236 /// Sometimes commit/abort
237 /// may cause selection clear(Sketch operation) as a result
238 /// it will be lost and is not used for preselection.
239 ModuleBase_ISelection* aSelection = myWorkshop->selection();
240 QList<ModuleBase_ViewerPrsPtr> aPreSelected =
241 aSelection->getSelected(ModuleBase_ISelection::AllControls);
243 myClickedSketchPoint = PartSet_Tools::getPnt2d(theEvent, theWindow,
244 module()->sketchMgr()->activeSketch());
245 FeaturePtr anExternalCreatedFeature;
246 if (!aPreSelected.empty()) {
247 ModuleBase_ViewerPrsPtr aValue = aPreSelected.first();
248 module()->getGeomSelection(aValue, mySelectedObject, mySelectedAttribute);
250 PartSet_WidgetPoint2D* aPointWidget = dynamic_cast<PartSet_WidgetPoint2D*>(anActiveWidget);
253 aPointWidget->getGeomSelection_(aValue, mySelectedObject, aShape);
254 ObjectPtr anExternalObject =
255 aPointWidget->getExternalObjectMgr()->getExternalObjectValidated();
256 // if external object is during reentrant operation and is used as a parameter of feature
257 // it should be removed after the operation is restarted. (Circle feature, Projection)
258 if (anExternalObject.get())
259 anExternalCreatedFeature = ModelAPI_Feature::feature(anExternalObject);
264 // remove created external feature
265 if (anExternalCreatedFeature.get()) {
266 QObjectPtrList anObjects;
267 anObjects.append(anExternalCreatedFeature);
268 workshop()->deleteFeatures(anObjects);
271 myClickedSketchPoint = std::shared_ptr<GeomAPI_Pnt2d>();
272 mySelectedObject = ObjectPtr();
273 mySelectedAttribute = AttributePtr();
275 myPreviousFeature = FeaturePtr();
278 // fill the first widget by the mouse event point
279 // if the active widget is not the first, it means that the restarted operation is filled by
280 // the current preselection.
281 PartSet_MouseProcessor* aMouseProcessor = dynamic_cast<PartSet_MouseProcessor*>(
282 module()->activeWidget());
283 //PartSet_WidgetPoint2D* aPoint2DWdg =
284 // dynamic_cast<PartSet_WidgetPoint2D*>(module()->activeWidget());
285 PartSet_MouseProcessor* aFirstWidget = dynamic_cast<PartSet_MouseProcessor*>(
286 aPanel->findFirstAcceptingValueWidget());
287 //if (aPoint2DWdg && aPoint2DWdg == aFirstWidget) {
288 if (aMouseProcessor && aMouseProcessor == aFirstWidget) {
289 std::shared_ptr<ModuleBase_ViewerPrs> aSelectedPrs;
290 if (!aPreSelected.empty())
291 aSelectedPrs = aPreSelected.front();
292 if (aSelectedPrs.get() && aSelectedPrs->object().get()
293 && !aSelectedPrs->object()->data()->isValid()) {
294 // the selected object was removed diring restart, e.g. presentable macro feature
295 // there are created objects to replace the object depending on created feature kind
296 aSelectedPrs = std::shared_ptr<ModuleBase_ViewerPrs>();
298 aMouseProcessor->setPreSelection(aSelectedPrs, theWindow, theEvent);
299 //aPoint2DWdg->mouseReleased(theWindow, theEvent);
300 //if (!aPreSelected.empty())
301 // aPoint2DWdg->setPreSelection(ModuleBase_ViewerPrsPtr());
303 // unblock viewer update
304 ModuleBase_Tools::blockUpdateViewer(false);
310 //******************************************************
311 void PartSet_SketcherReentrantMgr::setReentrantPreSelection(
312 const std::shared_ptr<Events_Message>& theMessage)
314 ReentrantMessagePtr aReentrantMessage =
315 std::dynamic_pointer_cast<ModelAPI_EventReentrantMessage>(theMessage);
316 if (!aReentrantMessage.get())
319 // if feature has already filled the selected object, we should not overwrite it
320 if (!aReentrantMessage->selectedObject().get())
321 aReentrantMessage->setSelectedObject(mySelectedObject);
323 aReentrantMessage->setSelectedAttribute(mySelectedAttribute);
324 aReentrantMessage->setClickedPoint(myClickedSketchPoint);
327 //void PartSet_SketcherReentrantMgr::onWidgetActivated()
329 // if (!isActiveMgr())
331 // if (!myIsInternalEditOperation)
334 // PartSet_Module* aModule = module();
335 // ModuleBase_ModelWidget* aFirstWidget = aModule->activeWidget();
336 // ModuleBase_IPropertyPanel* aPanel = aModule->currentOperation()->propertyPanel();
337 // if (aFirstWidget != aPanel->activeWidget()) {
338 // ModuleBase_WidgetSelector* aWSelector = dynamic_cast<ModuleBase_WidgetSelector*>
341 // myWorkshop->selectionActivate()->updateSelectionModesAndFilters(aWSelector);
346 void PartSet_SketcherReentrantMgr::onNoMoreWidgets(const std::string& thePreviousAttributeID)
349 std::cout << "PartSet_SketcherReentrantMgr::onNoMoreWidgets" << std::endl;
355 // we should avoid processing of the signal about no more widgets attributes and
356 // do this after the restart operaion is finished if it was called
357 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
358 // if it should be called after restart
359 if (myIsFlagsBlocked) {
360 myNoMoreWidgetsAttribute = thePreviousAttributeID;
364 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
365 (myWorkshop->currentOperation());
366 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
369 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
370 if (aFOperation->isNeedToBeAborted()) {
371 aFOperation->abort();
374 bool isStarted = false;
375 if (!module()->sketchMgr()->sketchSolverError()) {
376 if (myRestartingMode != RM_Forbided) {
377 myRestartingMode = RM_LastFeatureUsed;
378 isStarted = startInternalEdit(thePreviousAttributeID);
382 aFOperation->commit();
387 bool PartSet_SketcherReentrantMgr::processEnter(const std::string& thePreviousAttributeID)
394 // empty previous attribute means that the Apply/Ok button has focus and the enter
395 // should not lead to start edition mode of the previous operation
396 if (thePreviousAttributeID.empty())
399 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
400 (myWorkshop->currentOperation());
401 if (!myWorkshop->module()->getFeatureError(aFOperation->feature()).isEmpty())
404 bool isSketchSolverError = module()->sketchMgr()->sketchSolverError();
406 if (!isSketchSolverError) {
407 myRestartingMode = RM_EmptyFeatureUsed;
408 isDone = startInternalEdit(thePreviousAttributeID);
414 void PartSet_SketcherReentrantMgr::onVertexSelected()
419 ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
420 std::string anOperationId = anOperation->id().toStdString();
421 if (anOperationId == SketchPlugin_Line::ID() ||
422 isTangentArc(anOperation, module()->sketchMgr()->activeSketch())) {
423 /// If last line finished on vertex the lines creation sequence has to be break
424 ModuleBase_IPropertyPanel* aPanel = anOperation->propertyPanel();
425 ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
426 const QList<ModuleBase_ModelWidget*>& aWidgets = aPanel->modelWidgets();
427 QList<ModuleBase_ModelWidget*>::const_iterator anIt = aWidgets.begin(), aLast = aWidgets.end();
428 bool aFoundWidget = false;
429 bool aFoundObligatory = false;
430 for (; anIt != aLast && !aFoundObligatory; anIt++) {
432 aFoundWidget = *anIt == anActiveWidget;
434 aFoundObligatory = (*anIt)->isObligatory();
436 if (!aFoundObligatory)
437 myRestartingMode = RM_Forbided;
441 void PartSet_SketcherReentrantMgr::onAfterValuesChangedInPropertyPanel()
444 if (isInternalEditActive()) {
445 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
446 (myWorkshop->currentOperation());
447 ModuleBase_ModelWidget* aWidget = (ModuleBase_ModelWidget*)sender();
448 if (!aWidget->isModifiedInEdit().empty())
453 void PartSet_SketcherReentrantMgr::onBeforeStopped()
455 if (!isActiveMgr() || !myIsInternalEditOperation)
458 beforeStopInternalEdit();
461 bool PartSet_SketcherReentrantMgr::canBeCommittedByPreselection()
463 return !isActiveMgr() || myRestartingMode == RM_None;
466 bool PartSet_SketcherReentrantMgr::isActiveMgr() const
468 ModuleBase_Operation* aCurrentOperation = myWorkshop->currentOperation();
470 bool anActive = PartSet_SketcherMgr::isSketchOperation(aCurrentOperation);
472 anActive = module()->sketchMgr()->isNestedSketchOperation(aCurrentOperation);
473 if (anActive) { // the manager is not active when the current operation is a usual Edit
474 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
475 (myWorkshop->currentOperation());
476 if (aFOperation->isEditOperation())
477 anActive = myIsInternalEditOperation;
483 bool PartSet_SketcherReentrantMgr::startInternalEdit(const std::string& thePreviousAttributeID)
486 std::cout << "PartSet_SketcherReentrantMgr::startInternalEdit" << std::endl;
490 /// this is workaround for ModuleBase_WidgetEditor, used in SALOME mode. Sometimes key enter
491 /// event comes two times, so we should not start another internal edit operation
492 /// the Apply button becomes disabled becase the second additional internal feature is created
493 if (myIsInternalEditOperation)
496 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
497 (myWorkshop->currentOperation());
499 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
500 /// improvement to deselect automatically all eventual selected objects, when
501 // returning to the neutral point of the Sketcher or start internal edit
502 workshop()->selector()->clearSelection();
504 aFOperation->setEditOperation(true/*, false*/);
505 createInternalFeature();
507 myIsInternalEditOperation = true;
508 updateAcceptAllAction();
511 connect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
512 connect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
514 // activate selection filters of the first widget in the viewer
515 //onWidgetActivated();
517 // activate the last active widget in the Property Panel
518 if (!thePreviousAttributeID.empty()) {
519 ModuleBase_Operation* anEditOperation = module()->currentOperation();
520 if (anEditOperation) {
521 ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
522 ModuleBase_ModelWidget* aPreviousAttributeWidget = 0;
523 QList<ModuleBase_ModelWidget*> aWidgets = aPanel->modelWidgets();
524 for (int i = 0, aNb = aWidgets.size(); i < aNb && !aPreviousAttributeWidget; i++) {
525 if (aWidgets[i]->attributeID() == thePreviousAttributeID) {
526 /// workaround for the same attributes used in different stacked widgets(attribute types)
527 if (ModuleBase_ToolBox::isOffToolBoxParent(aWidgets[i]))
529 aPreviousAttributeWidget = aWidgets[i];
532 // If the current widget is a selector, do nothing, it processes the mouse press
533 if (aPreviousAttributeWidget) {
534 if (!aPreviousAttributeWidget->isViewerSelector()) {
535 aPreviousAttributeWidget->focusTo();
536 aPreviousAttributeWidget->emitFocusInWidget();
537 aPreviousAttributeWidget->selectContent();
540 // in case of shape multi selector, the widget does not lose focus by filling
541 // like it is in shape selector. So, if enter is pressed, the multi shape selector
542 // control should be deactivated. The focus is moved to Apply button and there
543 // should not be active control visualized in property panel
544 if (aPreviousAttributeWidget == aPanel->activeWidget()) {
545 aPanel->activateWidget(NULL, false);
547 // if there is no the next widget to be automatically activated,
548 // the Ok button in property
549 // panel should accept the focus(example is parallel constraint on sketch lines)
550 QToolButton* anOkBtn =
551 dynamic_cast<XGUI_PropertyPanel*>(aPanel)->findButton(PROP_PANEL_OK);
553 ModuleBase_Tools::setFocus(anOkBtn, "XGUI_PropertyPanel::activateNextWidget");
560 module()->sketchMgr()->clearClickedFlags();
565 void PartSet_SketcherReentrantMgr::beforeStopInternalEdit()
567 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
568 (myWorkshop->currentOperation());
570 disconnect(aFOperation, SIGNAL(beforeCommitted()), this, SLOT(onBeforeStopped()));
571 disconnect(aFOperation, SIGNAL(beforeAborted()), this, SLOT(onBeforeStopped()));
574 deleteInternalFeature();
577 void PartSet_SketcherReentrantMgr::restartOperation()
580 std::cout << "PartSet_SketcherReentrantMgr::restartOperation" << std::endl;
583 if (myIsInternalEditOperation) {
584 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(
585 myWorkshop->currentOperation());
587 ModuleBase_ISelection* aSelection = myWorkshop->selection();
588 QList<ModuleBase_ViewerPrsPtr> aPreSelected =
589 aSelection->getSelected(ModuleBase_ISelection::AllControls);
591 if (myInternalFeature.get())
592 copyReetntrantAttributes(myInternalFeature, aFOperation->feature(),
593 module()->sketchMgr()->activeSketch());
595 myNoMoreWidgetsAttribute = "";
596 myIsFlagsBlocked = true;
597 /// launch has 'false' parameter to do not start new operation if the previous operation
598 /// is not committed. It is important for Line Sketch feature as it uses the previous
599 /// created feature parameter(to build coincidence), but by abort the previous is removed
600 module()->launchOperation(aFOperation->id(), true);
601 myIsFlagsBlocked = false;
604 // we should avoid processing of the signal about no more widgets attributes and
605 // do this after the restart operaion is finished if it was called
606 // onNoMoreWidgets depends on myIsFlagsBlocked and fill myNoMoreWidgetsAttribute
607 // if it should be called after restart
608 if (!myNoMoreWidgetsAttribute.empty()) {
609 onNoMoreWidgets(myNoMoreWidgetsAttribute);
610 myNoMoreWidgetsAttribute = "";
616 void PartSet_SketcherReentrantMgr::createInternalFeature()
618 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
619 (myWorkshop->currentOperation());
621 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
622 FeaturePtr anOperationFeature = aFOperation->feature();
624 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
625 myInternalFeature = aSketch->addFeature(anOperationFeature->getKind());
628 std::cout << "PartSet_SketcherReentrantMgr::createInternalFeature: "
629 << myInternalFeature->data()->name() << std::endl;
632 bool isFeatureChanged = copyReetntrantAttributes(anOperationFeature, myInternalFeature,
634 XGUI_PropertyPanel* aPropertyPanel = dynamic_cast<XGUI_PropertyPanel*>
635 (aFOperation->propertyPanel());
637 myInternalWidget = new QWidget(aPropertyPanel->contentWidget()->pageWidget());
638 myInternalWidget->setVisible(false);
640 ModuleBase_PageWidget* anInternalPage = new ModuleBase_PageWidget(myInternalWidget);
642 QString aXmlRepr = aFOperation->getDescription()->xmlRepresentation();
643 ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myWorkshop);
645 aFactory.createWidget(anInternalPage);
646 QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
648 foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
649 bool isStoreValue = !aFOperation->isEditOperation() &&
650 !aWidget->getDefaultValue().empty() &&
651 !aWidget->isComputedDefault();
652 aWidget->setFeature(myInternalFeature, isStoreValue);
653 if (!isStoreValue && isFeatureChanged)
654 aWidget->restoreValue();
657 ModuleBase_ModelWidget* aFirstWidget = ModuleBase_IPropertyPanel::findFirstAcceptingValueWidget
660 setInternalActiveWidget(aFirstWidget);
664 void PartSet_SketcherReentrantMgr::deleteInternalFeature()
667 std::cout << "PartSet_SketcherReentrantMgr::deleteInternalFeature: "
668 << myInternalFeature->data()->name() << std::endl;
670 setInternalActiveWidget(0);
671 delete myInternalWidget;
672 myInternalWidget = 0;
674 QObjectPtrList anObjects;
675 anObjects.append(myInternalFeature);
676 workshop()->deleteFeatures(anObjects);
677 myInternalFeature = FeaturePtr();
680 void PartSet_SketcherReentrantMgr::resetFlags()
682 if (!myIsFlagsBlocked) {
683 myIsInternalEditOperation = false;
684 updateAcceptAllAction();
685 myRestartingMode = RM_None;
686 myReentrantMessage = std::shared_ptr<Events_Message>();
690 bool PartSet_SketcherReentrantMgr::copyReetntrantAttributes(const FeaturePtr& theSourceFeature,
691 const FeaturePtr& theNewFeature,
692 const CompositeFeaturePtr& theSketch,
693 const bool /*isTemporary*/)
695 bool aChanged = false;
696 if (!theSourceFeature.get() || !theSourceFeature->data().get() ||
697 !theSourceFeature->data()->isValid())
701 std::cout << "PartSet_SketcherReentrantMgr::copyReetntrantAttributes from '"
702 << theSourceFeature->data()->name() << "' to '" << theNewFeature->data()->name()
706 std::string aFeatureKind = theSourceFeature->getKind();
707 /*if (aFeatureKind == SketchPlugin_Line::ID()) {
708 // Initialize new line with first point equal to end of previous
709 std::shared_ptr<ModelAPI_Data> aSFData = theSourceFeature->data();
710 std::shared_ptr<GeomDataAPI_Point2D> aSPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
711 aSFData->attribute(SketchPlugin_Line::END_ID()));
712 std::shared_ptr<ModelAPI_Data> aNFData = theNewFeature->data();
713 std::shared_ptr<GeomDataAPI_Point2D> aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
714 aNFData->attribute(SketchPlugin_Line::START_ID()));
715 aNPoint->setValue(aSPoint->x(), aSPoint->y());
716 PartSet_Tools::createConstraint(theSketch, aSPoint, aNPoint);
718 aNPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
719 aSFData->attribute(SketchPlugin_Line::END_ID()));
720 aNPoint->setValue(aSPoint->x(), aSPoint->y());
722 else*/ if (aFeatureKind == SketchPlugin_MacroCircle::ID()) {
724 /*std::string aTypeAttributeId = SketchPlugin_MacroCircle::CIRCLE_TYPE();
725 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
726 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
727 if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
728 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());
729 //ModuleBase_Tools::flushUpdated(theNewFeature);*/
732 else if (aFeatureKind == SketchPlugin_MacroArc::ID()) {
734 /*std::string aTypeAttributeId = SketchPlugin_MacroArc::ARC_TYPE();
735 AttributeStringPtr aSourceFeatureTypeAttr = theSourceFeature->data()->string(aTypeAttributeId);
736 AttributeStringPtr aNewFeatureTypeAttr = theNewFeature->data()->string(aTypeAttributeId);
737 if (aNewFeatureTypeAttr->value() != aTypeAttributeId) // do nothing if there is no changes
738 aNewFeatureTypeAttr->setValue(aSourceFeatureTypeAttr->value());*/
739 //// if the arc is tangent, set coincidence to end point of the previous arc
740 //std::string anArcType = aSourceFeatureTypeAttr->value();
741 //if (anArcType == SketchPlugin_Arc::ARC_TYPE_TANGENT()) {
742 // // get the last point of the previuos arc feature(geom point 2d)
743 // std::shared_ptr<ModelAPI_Data> aSData = theSourceFeature->data();
744 // std::shared_ptr<GeomDataAPI_Point2D> aSPointAttr =
745 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
746 // aSData->attribute(SketchPlugin_Arc::END_ID()));
747 // // get point attribute on the current feature
748 // AttributeRefAttrPtr aTangentPointAttr = theNewFeature->data()->refattr(
749 // SketchPlugin_Arc::TANGENT_POINT_ID());
750 // aTangentPointAttr->setAttr(aSPointAttr);
752 // std::shared_ptr<GeomDataAPI_Point2D> aNPointAttr =
753 // std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
754 // theNewFeature->data()->attribute(SketchPlugin_Arc::END_ID()));
755 // aNPointAttr->setValue(aSPointAttr->x(), aSPointAttr->y());
758 //ModuleBase_Tools::flushUpdated(theNewFeature);
761 else if (aFeatureKind == SketchPlugin_Trim::ID() ||
762 aFeatureKind == SketchPlugin_Split::ID()) {
763 std::string aPreviewObjectAttribute = aFeatureKind == SketchPlugin_Trim::ID() ?
764 SketchPlugin_Trim::PREVIEW_OBJECT(): SketchPlugin_Split::PREVIEW_OBJECT();
765 std::string aPreviewPointAttribute = aFeatureKind == SketchPlugin_Trim::ID() ?
766 SketchPlugin_Trim::PREVIEW_POINT(): SketchPlugin_Split::PREVIEW_POINT();
767 std::shared_ptr<ModelAPI_AttributeReference> aRefPreviewAttr =
768 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
769 theSourceFeature->data()->attribute(aPreviewObjectAttribute));
770 std::shared_ptr<ModelAPI_AttributeReference> aNRefPreviewAttr =
771 std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
772 theNewFeature->data()->attribute(aPreviewObjectAttribute));
773 aNRefPreviewAttr->setValue(aRefPreviewAttr->value());
774 std::shared_ptr<GeomDataAPI_Point2D> aPointPreviewAttr =
775 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
776 theSourceFeature->data()->attribute(aPreviewPointAttribute));
777 std::shared_ptr<GeomDataAPI_Point2D> aNPointPreviewAttr =
778 std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
779 theNewFeature->data()->attribute(aPreviewPointAttribute));
780 aNPointPreviewAttr->setValue(aPointPreviewAttr->x(), aPointPreviewAttr->y());
785 bool PartSet_SketcherReentrantMgr::isTangentArc(ModuleBase_Operation* theOperation,
786 const CompositeFeaturePtr& /*theSketch*/) const
788 bool aTangentArc = false;
789 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
791 if (aFOperation && module()->sketchMgr()->isNestedSketchOperation(aFOperation)) {
792 FeaturePtr aFeature = aFOperation->feature();
793 if (aFeature.get() && aFeature->getKind() == SketchPlugin_MacroArc::ID()) {
794 AttributeStringPtr aTypeAttr = aFeature->data()->string(SketchPlugin_MacroArc::ARC_TYPE());
795 std::string anArcType = aTypeAttr.get() ? aTypeAttr->value() : "";
796 aTangentArc = anArcType == SketchPlugin_MacroArc::ARC_TYPE_BY_TANGENT_EDGE();
802 void PartSet_SketcherReentrantMgr::updateAcceptAllAction()
804 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
806 workshop()->errorMgr()->updateAcceptAllAction(aSketch);
809 XGUI_Workshop* PartSet_SketcherReentrantMgr::workshop() const
811 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
812 return aConnector->workshop();
815 PartSet_Module* PartSet_SketcherReentrantMgr::module() const
817 return dynamic_cast<PartSet_Module*>(myWorkshop->module());
820 void PartSet_SketcherReentrantMgr::setInternalActiveWidget(ModuleBase_ModelWidget* theWidget)
822 ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
823 (myWorkshop->currentOperation());
826 XGUI_PropertyPanel* aPropertyPanel = dynamic_cast<XGUI_PropertyPanel*>
827 (aFOperation->propertyPanel());
829 aPropertyPanel->setInternalActiveWidget(theWidget);
833 void PartSet_SketcherReentrantMgr::onAutoConstraints(bool isOn)
835 myIsAutoConstraints = isOn;
838 void PartSet_SketcherReentrantMgr::addConstraints(const FeaturePtr& theFeature)
840 static GeomDir2dPtr myHorDir(new GeomAPI_Dir2d(1, 0));
841 static GeomDir2dPtr myVertDir(new GeomAPI_Dir2d(0, 1));
843 if (theFeature->getKind() == SketchPlugin_Line::ID()) {
844 std::shared_ptr<ModelAPI_Data> aData = theFeature->data();
845 std::shared_ptr<GeomDataAPI_Point2D> aPoint1 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
846 aData->attribute(SketchPlugin_Line::START_ID()));
847 std::shared_ptr<GeomDataAPI_Point2D> aPoint2 = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
848 aData->attribute(SketchPlugin_Line::END_ID()));
849 if (aPoint1.get() && aPoint2.get()) {
850 GeomLine2dPtr aLine(new GeomAPI_Lin2d(aPoint1->pnt(), aPoint2->pnt()));
851 GeomDir2dPtr aDir = aLine->direction();
852 double aHorAngle = fabs(myHorDir->angle(aDir));
853 double aVertAngle = fabs(myVertDir->angle(aDir));
854 if (aHorAngle > M_PI/2.)
855 aHorAngle = M_PI - aHorAngle;
856 if (aVertAngle > M_PI/2.)
857 aVertAngle = M_PI - aVertAngle;
859 double aTolerance = Config_PropManager::real(SKETCH_TAB_NAME, "angular_tolerance");
860 CompositeFeaturePtr aSketch = module()->sketchMgr()->activeSketch();
862 if (aHorAngle < aTolerance)
863 // Add horizontal constraint
864 aFeature = aSketch->addFeature(SketchPlugin_ConstraintHorizontal::ID());
865 else if (aVertAngle < aTolerance)
866 // Add vertical constraint
867 aFeature = aSketch->addFeature(SketchPlugin_ConstraintVertical::ID());
869 if (aFeature.get()) {
870 aFeature->refattr(SketchPlugin_Constraint::ENTITY_A())->setObject(
871 theFeature->firstResult());