Salome HOME
2d060e83d5643d58099772fdb9fff30908209950
[modules/shaper.git] / src / XGUI / XGUI_PropertyPanel.cpp
1 // Copyright (C) 2014-2021  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include <XGUI_ActionsMgr.h>
21 #include <XGUI_ActiveControlMgr.h>
22 #include <XGUI_SelectionActivate.h>
23 #include <XGUI_ActiveControlSelector.h>
24 #include <XGUI_PropertyPanel.h>
25 #include <XGUI_PropertyPanelSelector.h>
26 #include <XGUI_OperationMgr.h>
27 #include <XGUI_Tools.h>
28 #include <XGUI_Workshop.h>
29
30 //#include <AppElements_Constants.h>
31 #include <ModuleBase_WidgetMultiSelector.h>
32 #include <ModuleBase_Tools.h>
33 #include <ModuleBase_PageBase.h>
34 #include <ModuleBase_PageWidget.h>
35 #include <ModuleBase_WidgetFactory.h>
36 #include <ModuleBase_OperationDescription.h>
37 #include <ModuleBase_Events.h>
38 #include <ModuleBase_IModule.h>
39 #include <ModuleBase_IWorkshop.h>
40
41 #include <Events_Loop.h>
42
43 #include <ModelAPI_Session.h>
44 #include <ModelAPI_Validator.h>
45
46 #include <QEvent>
47 #include <QFrame>
48 #include <QIcon>
49 #include <QKeyEvent>
50 #include <QLayoutItem>
51 #include <QToolButton>
52 #include <QVBoxLayout>
53 #include <QGridLayout>
54 #include <QWidget>
55 #include <QAction>
56 #include <QScrollArea>
57
58 #ifdef _DEBUG
59 #include <iostream>
60 #endif
61
62 //#define DEBUG_TAB_WIDGETS
63
64 //#define DEBUG_ACTIVE_WIDGET
65
66 XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent, XGUI_OperationMgr* theMgr)
67     : ModuleBase_IPropertyPanel(theParent),
68     myPanelPage(NULL),
69     myActiveWidget(NULL),
70     myPreselectionWidget(NULL),
71     myInternalActiveWidget(NULL),
72     myOperationMgr(theMgr)
73 {
74   setWindowTitle(tr("Property Panel"));
75   //MAYBE_UNUSED QAction* aViewAct = toggleViewAction();
76   setObjectName(PROP_PANEL);
77   setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
78
79   QWidget* aContent = new QWidget(this);
80   QGridLayout* aMainLayout = new QGridLayout(aContent);
81   const int kPanelColumn = 0;
82   int aPanelRow = 0;
83   aMainLayout->setContentsMargins(3, 3, 3, 3);
84   setWidget(aContent);
85
86   QFrame* aFrm = new QFrame(aContent);
87   aFrm->setFrameStyle(QFrame::Raised);
88   aFrm->setFrameShape(QFrame::Panel);
89   QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
90   ModuleBase_Tools::zeroMargins(aBtnLay);
91   aMainLayout->addWidget(aFrm, aPanelRow++, kPanelColumn);
92
93   myHeaderWidget = aFrm;
94
95   QStringList aBtnNames;
96   aBtnNames << QString(PROP_PANEL_HELP)
97     << QString(PROP_PANEL_OK)
98     << QString(PROP_PANEL_OK_PLUS)
99     << QString(PROP_PANEL_CANCEL);
100   foreach(QString eachBtnName, aBtnNames) {
101     QToolButton* aBtn = new QToolButton(aFrm);
102     aBtn->setObjectName(eachBtnName);
103     aBtn->setAutoRaise(true);
104     aBtnLay->addWidget(aBtn);
105   }
106   aBtnLay->insertStretch(1, 1);
107
108   myPanelPage = new ModuleBase_PageWidget(aContent);
109   myPanelPage->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
110   aMainLayout->addWidget(myPanelPage, aPanelRow, kPanelColumn);
111
112   // spit to make the preview button on the bottom of the panel
113   aMainLayout->setRowStretch(aPanelRow++, 1);
114
115   // preview button on the bottom of panel
116   aFrm = new QFrame(aContent);
117   aBtnLay = new QHBoxLayout(aFrm);
118   aBtnLay->addStretch(1);
119   ModuleBase_Tools::zeroMargins(aBtnLay);
120   aMainLayout->addWidget(aFrm, aPanelRow++, kPanelColumn);
121
122   QToolButton* aBtn = new QToolButton(aFrm);
123   aBtn->setObjectName(PROP_PANEL_PREVIEW);
124   aBtnLay->addWidget(aBtn);
125 }
126
127 XGUI_PropertyPanel::~XGUI_PropertyPanel()
128 {
129 }
130
131 void XGUI_PropertyPanel::cleanContent()
132 {
133   if (myActiveWidget)
134     myActiveWidget->deactivate();
135
136   XGUI_ActiveControlSelector* aPPSelector = XGUI_Tools::workshop(myOperationMgr->workshop())->
137     activeControlMgr()->getSelector(XGUI_PropertyPanelSelector::Type());
138   aPPSelector->reset(); // it removes need to be updated widget link
139
140   /// as the widgets are deleted later, it is important that the signals
141   /// of these widgets are not processed. An example of the error is issue 986.
142   /// In the given case, the property panel is firstly filled by new widgets
143   /// of restarted operation and after that the mouse release signal come from
144   /// the widget of the previous operation (Point2d widget about mouse is released
145   /// and focus is out of this widget)
146   QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(),
147                                                  aLast = myWidgets.end();
148   for (; anIt != aLast; anIt++) {
149     QWidget* aWidget = *anIt;
150     if (aWidget) {
151       aWidget->blockSignals(true);
152     }
153   }
154
155   myWidgets.clear();
156   myPanelPage->clearPage();
157   myActiveWidget = NULL;
158   emit propertyPanelDeactivated();
159   // VSV: It seems that this code is not necessary:
160   //      it is called on propertyPanelDeactivated() event
161   //myOperationMgr->workshop()->selectionActivate()->updateSelectionModes();
162   //myOperationMgr->workshop()->selectionActivate()->updateSelectionFilters();
163 #ifdef DEBUG_ACTIVE_WIDGET
164   std::cout << "myActiveWidget = NULL" << std::endl;
165 #endif
166
167   findButton(PROP_PANEL_PREVIEW)->setVisible(false); /// by default it is hidden
168   setWindowTitle(tr("Property Panel"));
169 }
170
171 void XGUI_PropertyPanel::setModelWidgets(const QList<ModuleBase_ModelWidget*>& theWidgets)
172 {
173   myWidgets = theWidgets;
174   if (theWidgets.empty())
175     return;
176   foreach (ModuleBase_ModelWidget* aWidget, theWidgets) {
177     connect(aWidget, SIGNAL(focusInWidget(ModuleBase_ModelWidget*)),
178             this,    SLOT(onFocusInWidget(ModuleBase_ModelWidget*)));
179     connect(aWidget, SIGNAL(focusOutWidget(ModuleBase_ModelWidget*)),
180             this,    SLOT(onActivateNextWidget(ModuleBase_ModelWidget*)));
181     connect(aWidget, SIGNAL(keyReleased(QObject*, QKeyEvent*)),
182             this,    SIGNAL(keyReleased(QObject*, QKeyEvent*)));
183     connect(aWidget, SIGNAL(enterClicked(QObject*)),
184             this,    SIGNAL(enterClicked(QObject*)));
185   }
186 }
187
188
189 const QList<ModuleBase_ModelWidget*>& XGUI_PropertyPanel::modelWidgets() const
190 {
191   return myWidgets;
192 }
193
194 ModuleBase_PageBase* XGUI_PropertyPanel::contentWidget()
195 {
196   return static_cast<ModuleBase_PageBase*>(myPanelPage);
197 }
198
199 void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
200 {
201   // Invalid feature case on abort of the operation
202   if (theFeature.get() == NULL)
203     return;
204   if (theFeature->isAction() || !theFeature->data())
205     return;
206   foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) {
207     if (!eachWidget->feature().get())
208       eachWidget->setFeature(theFeature);
209     eachWidget->restoreValue();
210   }
211   // the repaint is used here to immediately react in GUI to the values change.
212   update();
213 }
214
215 void XGUI_PropertyPanel::createContentPanel(FeaturePtr theFeature)
216 {
217   // Invalid feature case on abort of the operation
218   if (theFeature.get() == NULL)
219     return;
220   if (theFeature->isAction() || !theFeature->data())
221     return;
222
223   ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
224   if (myWidgets.empty()) {
225     QString aXmlRepr = anOperation->getDescription()->xmlRepresentation();
226
227     ModuleBase_WidgetFactory aFactory(aXmlRepr.toStdString(), myOperationMgr->workshop());
228     ModuleBase_PageBase* aPage = contentWidget();
229     aFactory.createPanel(aPage, theFeature);
230     // update model widgets if exist
231     setModelWidgets(aPage->modelWidgets());
232     // Apply button should be update if the feature was modified by the panel
233     myOperationMgr->onValidateOperation();
234   }
235   ModuleBase_OperationFeature* aFeatureOp =
236     dynamic_cast<ModuleBase_OperationFeature*>(anOperation);
237   if (aFeatureOp && (!aFeatureOp->isEditOperation()))
238     updateApplyPlusButton(theFeature);
239   else
240     findButton(PROP_PANEL_OK_PLUS)->setVisible(false);
241 }
242
243 void XGUI_PropertyPanel::updateApplyPlusButton(FeaturePtr theFeature)
244 {
245   if (theFeature.get()) {
246     std::shared_ptr<Config_FeatureMessage> aFeatureInfo =
247       myOperationMgr->workshop()->featureInfo(theFeature->getKind().c_str());
248     if (aFeatureInfo.get()) {
249       findButton(PROP_PANEL_OK_PLUS)->setVisible(aFeatureInfo->isApplyContinue());
250       return;
251     }
252   }
253   findButton(PROP_PANEL_OK_PLUS)->setVisible(false);
254 }
255
256 ModuleBase_ModelWidget* XGUI_PropertyPanel::activeWidget(const bool isUseCustomWidget) const
257 {
258   if (isUseCustomWidget && myInternalActiveWidget)
259     return myInternalActiveWidget;
260
261   return myActiveWidget;
262 }
263
264 void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget)
265 {
266   // it is possible that the property panel widgets have not been visualized
267   // (e.g. on start operation), so it is strictly important to do not check visualized state
268   activateNextWidget(theWidget, false);
269 }
270
271 void XGUI_PropertyPanel::onFocusInWidget(ModuleBase_ModelWidget* theWidget)
272 {
273 #ifdef DEBUG_ACTIVE_WIDGET
274   std::cout << "onFocusInWidget" << std::endl;
275 #endif
276   if (theWidget->canAcceptFocus())
277     activateWidget(theWidget);
278 }
279
280 void XGUI_PropertyPanel::onActivateNextWidget(ModuleBase_ModelWidget* theWidget)
281 {
282   // this slot happens when some widget lost focus, the next widget which accepts the focus
283   // should be shown, so the second parameter is true
284   // it is important for features where in cases the same attributes are used, isCase for this
285   // attribute returns true, however it can be placed in hidden stack widget(extrusion: elements,
286   // sketch multi rotation -> single/full point)
287   // it is important to check the widget visibility to do not check of the next widget visible
288   // state if the current is not shown. (example: sketch circle re-entrant operation after mouse
289   // release in the viewer, next, radius,
290   // widget should be activated but the first is not visualized)
291   bool isVisible = theWidget->isVisible();
292   activateNextWidget(theWidget, isVisible);
293 }
294
295
296 void XGUI_PropertyPanel::activateNextWidget(ModuleBase_ModelWidget* theWidget,
297                                             const bool isCheckVisibility)
298 {
299   // TO CHECK: Editing operation does not have automatical activation of widgets
300   if (isEditingMode()) {
301     activateWidget(NULL);
302     return;
303   }
304   ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
305
306   QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
307   bool isFoundWidget = false;
308   ModuleBase_Tools::activateWindow(this, "XGUI_PropertyPanel::activateNextWidget()");
309   for (; anIt != aLast; anIt++) {
310     ModuleBase_ModelWidget* aCurrentWidget = *anIt;
311     if (isFoundWidget || !theWidget) {
312
313       if (!aValidators->isCase(aCurrentWidget->feature(), aCurrentWidget->attributeID()))
314         continue; // this attribute does not participate in the current case
315       if (isCheckVisibility && !aCurrentWidget->isInternal()) {
316         if (!aCurrentWidget->isVisible())
317           continue;
318       }
319       if (!aCurrentWidget->isObligatory())
320         continue; // not obligatory widgets are not activated automatically
321
322       if (!aCurrentWidget->canAcceptFocus())
323         continue; // do not set focus if it can not be accepted, case: optional choice
324
325       if (aCurrentWidget->focusTo()) {
326         aCurrentWidget->emitFocusInWidget();
327         return;
328       }
329     }
330     isFoundWidget = isFoundWidget || (*anIt) == theWidget;
331   }
332   // set focus to Ok/Cancel button in Property panel if there are no more active widgets
333   // it should be performed before activateWidget(NULL) because it emits some signals which
334   // can be processed by moudule for example as to activate another widget with setting focus
335   QWidget* aNewFocusWidget = 0;
336   QToolButton* anOkBtn = findButton(PROP_PANEL_OK);
337   if (anOkBtn->isEnabled())
338     aNewFocusWidget = anOkBtn;
339   else {
340     QToolButton* aCancelBtn = findButton(PROP_PANEL_CANCEL);
341     if (aCancelBtn->isEnabled())
342       aNewFocusWidget = aCancelBtn;
343   }
344   if (aNewFocusWidget)
345     ModuleBase_Tools::setFocus(aNewFocusWidget, "XGUI_PropertyPanel::activateNextWidget");
346
347   activateWidget(NULL);
348 }
349
350 void findDirectChildren(QWidget* theParent, QList<QWidget*>& theWidgets, const bool theDebug)
351 {
352   QList<QWidget*> aWidgets;
353
354   if (theParent) {
355     QLayout* aLayout = theParent->layout();
356     if (aLayout) {
357       for (int i = 0, aCount = aLayout->count(); i < aCount; i++) {
358         QLayoutItem* anItem = aLayout->itemAt(i);
359         QWidget* aWidget = anItem ? anItem->widget() : 0;
360         if (aWidget) {
361           if (aWidget->isVisible()) {
362             if (aWidget->focusPolicy() != Qt::NoFocus)
363               theWidgets.append(aWidget);
364             findDirectChildren(aWidget, theWidgets, false);
365           }
366         }
367         else if (anItem->layout()) {
368           QLayout* anItemLayout = anItem->layout();
369           for (int it = 0, cnt = anItemLayout->count(); it < cnt; it++) {
370             QLayoutItem* aCurItem = anItemLayout->itemAt(it);
371             QWidget* aCurWidget = aCurItem ? aCurItem->widget() : 0;
372             if (aCurWidget) {
373               if (aCurWidget->isVisible()) {
374                 if (aCurWidget->focusPolicy() != Qt::NoFocus)
375                   theWidgets.append(aCurWidget);
376                 findDirectChildren(aCurWidget, theWidgets, false);
377               }
378             }
379             else {
380               // TODO: improve recursive search for the case when here QLayout is used
381               // currently, the switch widget uses only 1 level of qlayout in qlayout using for
382               // example for construction plane feature. If there are more levels,
383               // it should be implemented here
384             }
385           }
386         }
387       }
388     }
389   }
390 #ifdef DEBUG_TAB_WIDGETS
391   if (theDebug) {
392     QStringList aWidgetTypes;
393     QList<QWidget*>::const_iterator anIt =  theWidgets.begin(), aLast = theWidgets.end();
394     for (; anIt != aLast; anIt++) {
395       QWidget* aWidget = *anIt;
396       if (aWidget)
397         aWidgetTypes.append(aWidget->objectName());
398     }
399     QString anInfo = QString("theWidgets[%1]: %2")
400       .arg(theWidgets.count()).arg(aWidgetTypes.join(","));
401     qDebug(anInfo.toStdString().c_str());
402   }
403 #endif
404 }
405
406 bool XGUI_PropertyPanel::setFocusNextPrevChild(bool theIsNext)
407 {
408   return focusNextPrevChild(theIsNext);
409 }
410
411 bool XGUI_PropertyPanel::focusNextPrevChild(bool theIsNext)
412 {
413   // it wraps the Tabs clicking to follow in the chain:
414   // controls, last control, Apply, Cancel, first control, controls
415   bool isChangedFocus = false;
416
417   QWidget* aFocusWidget = focusWidget();
418 #ifdef DEBUG_TAB_WIDGETS
419   if (aFocusWidget) {
420     QString anInfo = QString("focus Widget: %1").arg(aFocusWidget->objectName());
421     qDebug(anInfo.toStdString().c_str());
422   }
423 #endif
424   ModuleBase_ModelWidget* aFocusMWidget = ModuleBase_ModelWidget::findModelWidget(this,
425                                                                          aFocusWidget);
426   //if (aFocusMWidget)
427   //  aFocusMWidget->setHighlighted(false);
428
429   QWidget* aNewFocusWidget = 0;
430   if (aFocusWidget) {
431     QList<QWidget*> aChildren;
432     findDirectChildren(this, aChildren, true);
433     int aChildrenCount = aChildren.count();
434     int aFocusWidgetIndex = aChildren.indexOf(aFocusWidget);
435     QToolButton* anOkBtn = findButton(PROP_PANEL_OK);
436     if (aFocusWidgetIndex >= 0) {
437       if (theIsNext) {
438         if (aFocusWidgetIndex == aChildrenCount-1) {
439           // after the last widget focus should be set to "Apply"
440           if (anOkBtn->isEnabled())
441             aNewFocusWidget = anOkBtn;
442           else {
443             QToolButton* aCancelBtn = findButton(PROP_PANEL_CANCEL);
444             if (aCancelBtn->isEnabled())
445               aNewFocusWidget = aCancelBtn;
446           }
447         }
448         else {
449           aNewFocusWidget = aChildren[aFocusWidgetIndex+1];
450         }
451       }
452       else {
453         if (aFocusWidgetIndex == 0) {
454           // before the first widget, the last should accept focus
455           aNewFocusWidget = aChildren[aChildrenCount - 1];
456         }
457         else {
458           // before the "Apply" button, the last should accept focus for consistency with "Next"
459           if (aFocusWidget == anOkBtn) {
460             aNewFocusWidget = aChildren[aChildrenCount - 1];
461           }
462           else {
463             aNewFocusWidget = aChildren[aFocusWidgetIndex-1];
464           }
465         }
466       }
467     }
468   }
469   if (aNewFocusWidget) {
470     if (myActiveWidget) {
471       bool isFirstControl = !theIsNext;
472       QWidget* aLastFocusControl = myActiveWidget->getControlAcceptingFocus(isFirstControl);
473       if (aFocusWidget == aLastFocusControl) {
474         setActiveWidget(NULL, false);
475       }
476     }
477
478     // we want to have property panel as an active window to enter values in double control
479     ModuleBase_Tools::setFocus(aNewFocusWidget, "XGUI_PropertyPanel::focusNextPrevChild()");
480
481     ModuleBase_ModelWidget* aNewFocusMWidget = ModuleBase_ModelWidget::findModelWidget(this,
482                                                                               aNewFocusWidget);
483     if (aNewFocusMWidget) {
484       if (aFocusMWidget && (aFocusMWidget != aNewFocusMWidget)) {
485         aFocusMWidget->setHighlighted(false);
486       }
487       aNewFocusMWidget->emitFocusInWidget();
488       isChangedFocus = true;
489     }
490   }
491   return isChangedFocus;
492 }
493
494 void XGUI_PropertyPanel::activateNextWidget()
495 {
496   activateNextWidget(myActiveWidget);
497 }
498
499 void XGUI_PropertyPanel::activateWidget(ModuleBase_ModelWidget* theWidget, const bool theEmitSignal)
500 {
501   std::string aPreviosAttributeID;
502   if(myActiveWidget)
503     aPreviosAttributeID = myActiveWidget->attributeID();
504
505   // Avoid activation of already actve widget. It could happen on focusIn event many times
506   setActiveWidget(theWidget, theEmitSignal);
507 }
508
509 bool XGUI_PropertyPanel::setActiveWidget(ModuleBase_ModelWidget* theWidget, const bool isEmitSignal)
510 {
511   // Avoid activation of already actve widget. It could happen on focusIn event many times
512   if (theWidget == myActiveWidget) {
513     return false;
514   }
515   std::string aPreviosAttributeID;
516   ModuleBase_ModelWidget* aDeactivatedWidget = NULL, *anActivatedWidget = NULL;
517   if(myActiveWidget) {
518     aPreviosAttributeID = myActiveWidget->attributeID();
519     myActiveWidget->processValueState();
520     myActiveWidget->deactivate();
521     myActiveWidget->setHighlighted(false);
522     aDeactivatedWidget = myActiveWidget;
523   }
524   if(theWidget) {
525     emit beforeWidgetActivated(theWidget);
526     theWidget->setHighlighted(true);
527     theWidget->activate();
528     anActivatedWidget = theWidget;
529   }
530   myActiveWidget = theWidget;
531
532 #ifdef DEBUG_ACTIVE_WIDGET
533   std::cout << "myActiveWidget = " << (theWidget ? theWidget->context().c_str() : "") << std::endl;
534 #endif
535   bool aHasMoreWidgets = true;
536   if (isEmitSignal) {
537     //emit widgetActivated(myActiveWidget);
538     if (!myActiveWidget && !isEditingMode()) {
539       aHasMoreWidgets = false;
540       emit noMoreWidgets(aPreviosAttributeID);
541     }
542   }
543   if (myActiveWidget)
544     emit propertyPanelActivated();
545   // VSV: Do not deactivate whole property panel on non-active widget
546   // because it makes problem for continuing of projection operation
547   // because of redefinition of module selection filters while projection
548   // operation is not finished.
549   //else
550   //  emit propertyPanelDeactivated();
551   myOperationMgr->workshop()->selectionActivate()->updateSelectionModes();
552   myOperationMgr->workshop()->selectionActivate()->updateSelectionFilters();
553
554   if (aHasMoreWidgets && aDeactivatedWidget)
555     aDeactivatedWidget->updateAfterDeactivation();
556   if (aHasMoreWidgets && anActivatedWidget)
557     anActivatedWidget->updateAfterActivation();
558
559   if (aHasMoreWidgets && myActiveWidget)
560   {
561     // restore widget selection should be done after selection modes of widget activating
562     static Events_ID anEvent = Events_Loop::eventByName(EVENT_UPDATE_BY_WIDGET_SELECTION);
563     Events_Loop::loop()->flush(anEvent);
564   }
565   return true;
566 }
567
568 void XGUI_PropertyPanel::setFocusOnOkButton()
569 {
570   QToolButton* anOkBtn = findButton(PROP_PANEL_OK);
571   ModuleBase_Tools::setFocus(anOkBtn, "XGUI_PropertyPanel::setFocusOnOkButton()");
572 }
573
574 void XGUI_PropertyPanel::setCancelEnabled(bool theEnabled)
575 {
576   QToolButton* anCancelBtn = findButton(PROP_PANEL_CANCEL);
577   anCancelBtn->setEnabled(theEnabled);
578 }
579
580 bool XGUI_PropertyPanel::isCancelEnabled() const
581 {
582   QToolButton* anCancelBtn = findButton(PROP_PANEL_CANCEL);
583   return anCancelBtn->isEnabled();
584 }
585
586 void XGUI_PropertyPanel::setEditingMode(bool isEditing)
587 {
588   ModuleBase_IPropertyPanel::setEditingMode(isEditing);
589   foreach(ModuleBase_ModelWidget* aWgt, myWidgets) {
590     aWgt->setEditingMode(isEditing);
591   }
592 }
593
594 void XGUI_PropertyPanel::setupActions(XGUI_ActionsMgr* theMgr)
595 {
596   QStringList aButtonNames;
597   aButtonNames << PROP_PANEL_OK<< PROP_PANEL_OK_PLUS << PROP_PANEL_CANCEL
598                << PROP_PANEL_HELP << PROP_PANEL_PREVIEW;
599   QList<XGUI_ActionsMgr::OperationStateActionId> aActionIds;
600   aActionIds << XGUI_ActionsMgr::Accept << XGUI_ActionsMgr::AcceptPlus << XGUI_ActionsMgr::Abort
601              << XGUI_ActionsMgr::Help << XGUI_ActionsMgr::Preview;
602   for (int i = 0; i < aButtonNames.size(); ++i) {
603     QToolButton* aBtn = findButton(aButtonNames.at(i).toStdString().c_str());
604     QAction* anAct = theMgr->operationStateAction(aActionIds.at(i));
605     aBtn->setDefaultAction(anAct);
606   }
607 }
608
609 void XGUI_PropertyPanel::onAcceptData()
610 {
611   foreach (ModuleBase_ModelWidget* aWidget, myWidgets) {
612     aWidget->onFeatureAccepted();
613   }
614 }
615
616 void XGUI_PropertyPanel::setInternalActiveWidget(ModuleBase_ModelWidget* theWidget)
617 {
618   if (theWidget)
619   {
620     myInternalActiveWidget = theWidget;
621     emit propertyPanelActivated();
622   }
623   else
624   {
625     if (myInternalActiveWidget)
626     {
627       delete myInternalActiveWidget;
628       myInternalActiveWidget = 0;
629     }
630     emit propertyPanelDeactivated();
631   }
632   myOperationMgr->workshop()->selectionActivate()->updateSelectionModes();
633   myOperationMgr->workshop()->selectionActivate()->updateSelectionFilters();
634 }
635
636 ModuleBase_ModelWidget* XGUI_PropertyPanel::preselectionWidget() const
637 {
638   return myPreselectionWidget;
639 }
640
641 void XGUI_PropertyPanel::setPreselectionWidget(ModuleBase_ModelWidget* theWidget)
642 {
643   myPreselectionWidget = theWidget;
644 }
645
646
647 void XGUI_PropertyPanel::closeEvent(QCloseEvent* theEvent)
648 {
649   ModuleBase_Operation* aOp = myOperationMgr->currentOperation();
650   if (aOp) {
651     if (myOperationMgr->canStopOperation(aOp)) {
652       myOperationMgr->abortOperation(aOp);
653       if (myOperationMgr->hasOperation())
654         theEvent->ignore();
655       else
656         theEvent->accept();
657     } else
658       theEvent->ignore();
659   } else
660     ModuleBase_IPropertyPanel::closeEvent(theEvent);
661 }
662
663 QToolButton* XGUI_PropertyPanel::findButton(const char* theInternalName) const
664 {
665   return findChild<QToolButton*>(theInternalName);
666 }