ModuleBase_WidgetValidator.h
ModuleBase_IconFactory.h
ModuleBase_WidgetErrorLabel.h
+ ModuleBase_Dialog.h
)
SET(PROJECT_SOURCES
ModuleBase_IconFactory.cpp
ModuleBase_WidgetErrorLabel.cpp
ModuleBase_SelectionValidator.cpp
+ ModuleBase_Dialog.cpp
)
SET(PROJECT_LIBRARIES
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+
+#include "ModuleBase_Dialog.h"
+#include "ModuleBase_WidgetFactory.h"
+#include "ModuleBase_IWorkshop.h"
+#include "ModuleBase_IPropertyPanel.h"
+#include "ModuleBase_PageWidget.h"
+
+#include <ModelAPI_Session.h>
+
+#include <QMainWindow>
+#include <QLayout>
+#include <QDialogButtonBox>
+#include <QPushButton>
+
+
+ModuleBase_Dialog::ModuleBase_Dialog(ModuleBase_IWorkshop* theParent, const QString& theId,
+ const std::string& theDescription) :
+ QDialog(theParent->desktop()),
+ myId(theId),
+ myDescription(theDescription),
+ myWorkshop(theParent)
+{
+ ModuleBase_WidgetFactory aFactory(myDescription, myWorkshop);
+
+ SessionPtr aMgr = ModelAPI_Session::get();
+ std::shared_ptr<ModelAPI_Document> aDoc = aMgr->activeDocument();
+
+ aMgr->startOperation(myId.toStdString());
+ myFeature = aDoc->addFeature(myId.toStdString());
+ if (!myFeature.get())
+ return;
+
+ QVBoxLayout* aLayout = new QVBoxLayout(this);
+ aLayout->setContentsMargins(0, 0, 0, 0);
+ aLayout->setSpacing(1);
+ //setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
+
+ ModuleBase_PageWidget* aPage = new ModuleBase_PageWidget(this);
+ aLayout->addWidget(aPage);
+
+ aFactory.createWidget(aPage, false);
+ myWidgets = aFactory.getModelWidgets();
+ foreach (ModuleBase_ModelWidget* aWidget, myWidgets) {
+ initializeWidget(aWidget);
+ }
+
+ QFrame* aFrame = new QFrame(this);
+ aFrame->setFrameStyle(QFrame::WinPanel | QFrame::Raised);
+ aLayout->addWidget(aFrame);
+
+ QVBoxLayout* aBtnLayout = new QVBoxLayout(aFrame);
+ ModuleBase_Tools::adjustMargins(aBtnLayout);
+
+ QDialogButtonBox* aBtnBox = new QDialogButtonBox(
+ QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, aFrame);
+ aBtnLayout->addWidget(aBtnBox);
+
+ aBtnBox->button(QDialogButtonBox::Ok)->setIcon(QIcon(":pictures/button_ok.png"));
+ aBtnBox->button(QDialogButtonBox::Cancel)->setIcon(QIcon(":pictures/button_cancel.png"));
+
+ connect(aBtnBox, SIGNAL(accepted()), this, SLOT(accept()));
+ connect(aBtnBox, SIGNAL(rejected()), this, SLOT(reject()));
+
+
+}
+
+void ModuleBase_Dialog::initializeWidget(ModuleBase_ModelWidget* theWidget)
+{
+ theWidget->setFeature(myFeature);
+}
+
+void ModuleBase_Dialog::showEvent(QShowEvent* theEvent)
+{
+ QDialog::showEvent(theEvent);
+ if (myWidgets.length() > 0)
+ myWidgets.first()->activate();
+}
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#ifndef ModuleBase_Dialog_H
+#define ModuleBase_Dialog_H
+
+#include "ModuleBase.h"
+#include <ModelAPI_Feature.h>
+
+#include <QDialog>
+#include <string>
+
+
+class ModuleBase_IWorkshop;
+class ModuleBase_ModelWidget;
+
+/**
+ * \ingroup GUI
+ * A dialog box which is used for modal dialog box feature interface
+ */
+class ModuleBase_Dialog : public QDialog
+{
+ Q_OBJECT
+public:
+ ModuleBase_Dialog(ModuleBase_IWorkshop* theParent, const QString& theId,
+ const std::string& theDescription);
+
+protected:
+ virtual void showEvent(QShowEvent* theEvent);
+
+
+private:
+ void initializeWidget(ModuleBase_ModelWidget* theWidget);
+
+ QString myId;
+ std::string myDescription;
+ ModuleBase_IWorkshop* myWorkshop;
+ FeaturePtr myFeature;
+ QList<ModuleBase_ModelWidget*> myWidgets;
+};
+
+#endif
#include "ModuleBase_OperationDescription.h"
#include "ModuleBase_OperationFeature.h"
#include "ModuleBase_ModelWidget.h"
+#include "ModuleBase_WidgetFactory.h"
+#include "ModuleBase_PageWidget.h"
+#include "ModuleBase_Dialog.h"
#include <Events_Loop.h>
#include <Config_ModuleReader.h>
#include <QAction>
+#include <QMainWindow>
+#include <QDialog>
+#include <QLayout>
+#include <QDialogButtonBox>
+#include <QPushButton>
ModuleBase_IModule::ModuleBase_IModule(ModuleBase_IWorkshop* theParent)
: QObject(theParent), myWorkshop(theParent)
// SLOT(onMouseDoubleClick(QMouseEvent*)));
}
+void ModuleBase_IModule::launchModal(const QString& theCmdId)
+{
+ if (!myWorkshop->canStartOperation(theCmdId))
+ return;
+
+ std::string aXmlCfg, aDescription;
+ getXMLRepresentation(theCmdId.toStdString(), aXmlCfg, aDescription);
+
+ SessionPtr aMgr = ModelAPI_Session::get();
+ aMgr->startOperation(theCmdId.toStdString());
+
+ ModuleBase_Dialog aDlg(myWorkshop, theCmdId, aXmlCfg);
+ if (aDlg.exec() == QDialog::Accepted)
+ aMgr->finishOperation();
+ else
+ aMgr->abortOperation();
+ myWorkshop->updateCommandStatus();
+}
+
+
void ModuleBase_IModule::launchOperation(const QString& theCmdId)
{
if (!myWorkshop->canStartOperation(theCmdId))
}
}
else {
- launchOperation(aCmd->data().toString());
- emit operationLaunched();
+ QString aCmdId = aCmd->data().toString();
+ std::shared_ptr<Config_FeatureMessage> aInfo = myWorkshop->featureInfo(aCmdId);
+ if (aInfo.get() && aInfo->isModal()) {
+ launchModal(aCmdId);
+ } else {
+ launchOperation(aCmdId);
+ emit operationLaunched();
+ }
}
}
/// \param theCmdId the operation name\r
virtual void launchOperation(const QString& theCmdId);\r
\r
+ /// Executes feature as a modal dialog box\r
+ /// \param theCmdId the operation name\r
+ virtual void launchModal(const QString& theCmdId);\r
+\r
/// Realizes some functionality by an operation start\r
/// \param theOperation a started operation\r
virtual void operationStarted(ModuleBase_Operation* theOperation) {}\r
#include <ModelAPI_Object.h>
#include <GeomAPI_AISObject.h>
+#include <Config_FeatureMessage.h>
#include <QObject>
class ModuleBase_Operation;
class ModuleBase_FilterFactory;
class ModuleBase_ViewerPrs;
+class QMainWindow;
/**
* \ingroup GUI
/// Update of commands status
virtual void updateCommandStatus() = 0;
+ virtual std::shared_ptr<Config_FeatureMessage> featureInfo(const QString& theId) const = 0;
+
+ virtual QMainWindow* desktop() const = 0;
+
+
signals:
/// Signal selection changed.
void selectionChanged();
#include <ModuleBase_ModelWidget.h>
#include <ModuleBase_Tools.h>
-#include <QGridLayout>
+#include <QLayout>
#include <iostream>
ModuleBase_PageWidget::ModuleBase_PageWidget(QWidget* theParent)
: QFrame(theParent)
{
- myMainLayout = new QGridLayout(this);
+ myMainLayout = new QVBoxLayout(this);
ModuleBase_Tools::adjustMargins(myMainLayout);
setLayout(myMainLayout);
}
void ModuleBase_PageWidget::addPageStretch()
{
- myMainLayout->setRowStretch(myMainLayout->rowCount(), 1);
+ myMainLayout->addStretch(1);
}
void ModuleBase_PageWidget::placeModelWidget(ModuleBase_ModelWidget* theWidget)
{
- const int kCol = 0;
- const int kRow = myMainLayout->count();
- myMainLayout->addWidget(theWidget, kRow, kCol);
- myMainLayout->setRowStretch(kRow, 0);
+ myMainLayout->addWidget(theWidget, 0);
}
void ModuleBase_PageWidget::placeWidget(QWidget* theWidget)
#endif
return;
}
- const int kCol = 0;
- const int kRow = myMainLayout->count();
- myMainLayout->addWidget(theWidget, kRow, kCol);
- myMainLayout->setRowStretch(kRow, 0);
+ myMainLayout->addWidget(theWidget, 0);
}
QLayout* ModuleBase_PageWidget::pageLayout()
#include <QList>
class ModuleBase_ModelWidget;
-class QGridLayout;
+class QVBoxLayout;
/*!
* \ingroup GUI
virtual void addPageStretch();
private:
- QGridLayout* myMainLayout; ///< page's layout
+ QVBoxLayout* myMainLayout; ///< page's layout
};
#endif /* MODULEBASE_PAGEWIDGET_H_ */
delete myWidgetApi;
}
-void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage)
+void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage, bool alignToTop)
{
std::string aWType = myWidgetApi->widgetType();
if (aWType == NODE_FEATURE) {
}
} while (myWidgetApi->toNextWidget());
- thePage->alignToTop();
+ if (alignToTop)
+ thePage->alignToTop();
}
void ModuleBase_WidgetFactory::createPanel(ModuleBase_PageBase* thePage,
/// Creates content widget for property panel
/// \param thePage a parent page
- void createWidget(ModuleBase_PageBase* thePage);
+ void createWidget(ModuleBase_PageBase* thePage, bool alignToTop = true);
/// Creates property panel content for the feature
/// \param thePage a parent page
// Author: Vitaly SMETANNIKOV
#include "ParametersPlugin_WidgetParamsMgr.h"
+#include "ParametersPlugin_Parameter.h"
+
+#include <ModelAPI_ResultParameter.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_AttributeDouble.h>
#include <QLayout>
#include <QTreeWidget>
#include <QPushButton>
#include <QToolButton>
+#include <QStyledItemDelegate>
+#include <QPainter>
+
+enum ColumnType {
+ Col_Name,
+ Col_Equation,
+ Col_Result,
+ Col_Comment
+};
+
+class ParametersPlugin_ItemDelegate : public QStyledItemDelegate
+{
+public:
+ ParametersPlugin_ItemDelegate(QObject* thaParent) :
+ QStyledItemDelegate(thaParent) {}
+
+ virtual void paint(QPainter* painter,
+ const QStyleOptionViewItem& option,
+ const QModelIndex& index ) const;
+
+ //virtual QWidget* createEditor(QWidget* parent,
+ // const QStyleOptionViewItem& option,
+ // const QModelIndex& index) const;
+
+ bool isEditable(const QModelIndex& theIndex) const;
+};
+
+bool ParametersPlugin_ItemDelegate::isEditable(const QModelIndex& theIndex) const
+{
+ QModelIndex aParent = theIndex.parent();
+ if (aParent.isValid() && (aParent.row() == 0)) {
+ if (theIndex.column() == 2)
+ return false;
+ } else
+ return false;
+ return true;
+}
+
+void ParametersPlugin_ItemDelegate::paint(QPainter* painter,
+ const QStyleOptionViewItem& option,
+ const QModelIndex& index ) const
+{
+ QBrush aBrush = painter->brush();
+ QPen aPen = painter->pen();
+ if (!isEditable(index))
+ painter->setBrush(Qt::lightGray);
+
+ painter->setPen(Qt::darkGray);
+ painter->drawRect(option.rect);
+
+ QStyledItemDelegate::paint(painter, option, index);
+
+ painter->setPen(aPen);
+ painter->setBrush(aBrush);
+}
+
+
+//QWidget* ParametersPlugin_ItemDelegate::createEditor(QWidget* parent,
+// const QStyleOptionViewItem& option,
+// const QModelIndex& index) const
+//{
+// QWidget* aWgt = QStyledItemDelegate::createEditor(parent, option, index);
+// aWgt->setMinimumSize(option.rect.width() - option.decorationSize.width(),
+// option.rect.height());
+// return aWgt;
+//}
+
+
+/////////////////////////////////////////////////////////////////////////////////////////////////
ParametersPlugin_WidgetParamsMgr::ParametersPlugin_WidgetParamsMgr(QWidget* theParent, const Config_WidgetAPI* theData)
: ModuleBase_ModelWidget(theParent, theData)
QStringList aHeaders;
aHeaders << tr("Name") << tr("Equation") << tr("Result") << tr("Comment");
myTable->setHeaderLabels(aHeaders);
+ myTable->setColumnWidth(Col_Name, 200);
+ myTable->setColumnWidth(Col_Equation, 100);
+ myTable->setColumnWidth(Col_Result, 80);
+ myTable->setColumnWidth(Col_Comment, 200);
+ myTable->setMinimumWidth(600);
+ myTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
+ connect(myTable, SIGNAL(doubleClicked(const QModelIndex&)),
+ SLOT(onDoubleClick(const QModelIndex&)));
+ //myTable->viewport()->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum));
+
+ myDelegate = new ParametersPlugin_ItemDelegate(myTable);
+ connect(myDelegate, SIGNAL(closeEditor(QWidget*, QAbstractItemDelegate::EndEditHint)),
+ SLOT(onCloseEditor(QWidget*, QAbstractItemDelegate::EndEditHint)));
+
+ myTable->setItemDelegate(myDelegate);
aLayout->addWidget(myTable);
+ // Define root nodes
+ QStringList aNames;
+ aNames<<tr("Parameters");
+ myParameters = new QTreeWidgetItem(aNames);
+ myTable->addTopLevelItem(myParameters);
+
+ aNames.clear();
+ aNames<<tr("Features");
+ myFeatures = new QTreeWidgetItem(aNames);
+ myTable->addTopLevelItem(myFeatures);
+
QHBoxLayout* aBtnLayout = new QHBoxLayout(this);
QToolButton* aUpBtn = new QToolButton(this);
{
return true;
}
+
+void ParametersPlugin_WidgetParamsMgr::activateCustom()
+{
+ FeaturePtr aFeature = feature();
+ DocumentPtr aDoc = aFeature->document();
+ int aNbParam = aDoc->size(ModelAPI_ResultParameter::group());
+ ObjectPtr aObj;
+ QTreeWidgetItem* aItem;
+ ResultParameterPtr aParam;
+ FeaturePtr aParamFeature;
+ for (int i = 0; i < aNbParam; i++) {
+ aObj = aDoc->object(ModelAPI_ResultParameter::group(), i);
+ aParam = std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aObj);
+ if (aParam.get()) {
+ aParamFeature = ModelAPI_Feature::feature(aParam);
+
+ QStringList aValues;
+ aValues << aParamFeature->string(ParametersPlugin_Parameter::VARIABLE_ID())->value().c_str();
+ aValues << aParamFeature->string(ParametersPlugin_Parameter::EXPRESSION_ID())->value().c_str();
+
+ AttributeDoublePtr aValueAttribute = aParam->data()->real(ModelAPI_ResultParameter::VALUE());
+ aValues << QString::number(aValueAttribute->value());
+
+ //AttributeRefListPtr aParams = aParamFeature->reflist(ParametersPlugin_Parameter::ARGUMENTS_ID());
+ //std::list<ObjectPtr> aList = aParams->list();
+ //std::string aName;
+ //std::list<ObjectPtr>::iterator aIt;
+ //for(aIt = aList.begin(); aIt != aList.end(); aIt++) {
+ // aObj = (*aIt);
+ // aName = aObj->data()->name();
+ //}
+ aItem = new QTreeWidgetItem(aValues);
+ aItem->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
+ myParameters->addChild(aItem);
+
+ myFeatureList.append(aParamFeature);
+
+ const std::set<std::shared_ptr<ModelAPI_Attribute>>& aRefs = aParam->data()->refsToMe();
+ std::set<std::shared_ptr<ModelAPI_Attribute> >::const_iterator aIt;
+ for(aIt = aRefs.cbegin(); aIt != aRefs.cend(); aIt++) {
+ FeaturePtr aReferenced = std::dynamic_pointer_cast<ModelAPI_Feature>((*aIt)->owner());
+ if (aReferenced.get()) {
+ QStringList aValNames;
+ aValNames << aReferenced->data()->name().c_str();
+
+ //AttributeDoublePtr aValue = aReferenced->data()->real(SketchPlugin_Constraint::VALUE());
+ //aReferenced
+ aItem = new QTreeWidgetItem(aValNames);
+ myFeatures->addChild(aItem);
+ }
+ }
+ }
+ }
+ myFeatures->setExpanded(true);
+ myParameters->setExpanded(true);
+}
+
+
+void ParametersPlugin_WidgetParamsMgr::onDoubleClick(const QModelIndex& theIndex)
+{
+ if (myDelegate->isEditable(theIndex)) {
+ myTable->edit(theIndex);
+ myEditingIndex = theIndex;
+ }
+}
+
+void ParametersPlugin_WidgetParamsMgr::onCloseEditor(QWidget* theEditor,
+ QAbstractItemDelegate::EndEditHint theHint)
+{
+ if (myEditingIndex.column() == Col_Equation) {
+ QTreeWidgetItem* aItem = myParameters->child(myEditingIndex.row());
+ QString aText = aItem->text(myEditingIndex.column());
+ if (!aText.isEmpty()) {
+ FeaturePtr aFeature = myFeatureList.at(myEditingIndex.row());
+ AttributeStringPtr aStringAttr = aFeature->string(ParametersPlugin_Parameter::EXPRESSION_ID());
+ aStringAttr->setValue(aText.toStdString());
+ aFeature->execute();
+ ResultParameterPtr aResult =
+ std::dynamic_pointer_cast<ModelAPI_ResultParameter>(aFeature->firstResult());
+ if (aResult.get()) {
+ AttributeDoublePtr aValueAttribute =
+ aResult->data()->real(ModelAPI_ResultParameter::VALUE());
+ aItem->setText(Col_Result, QString::number(aValueAttribute->value()));
+ }
+ }
+ }
+ myEditingIndex = QModelIndex();
+}
\ No newline at end of file
#define ParametersPlugin_WidgetParamsMgr_H_
#include <ModuleBase_ModelWidget.h>
+#include <QModelIndex>
+#include <QAbstractItemDelegate>
class QTreeWidget;
+class QTreeWidgetItem;
+class ParametersPlugin_ItemDelegate;
/*!
* \ingroup GUI
/// Restore value from attribute data to the widget's control
virtual bool restoreValueCustom();
+ /// The method called when widget is activated
+ virtual void activateCustom();
+
+private slots:
+ void onDoubleClick(const QModelIndex&);
+ void onCloseEditor(QWidget* theEditor, QAbstractItemDelegate::EndEditHint theHint);
+
private:
QTreeWidget* myTable;
+ QTreeWidgetItem* myFeatures;
+ QTreeWidgetItem* myParameters;
+ ParametersPlugin_ItemDelegate* myDelegate;
+ QModelIndex myEditingIndex;
+
+ QList<FeaturePtr> myFeatureList;
};
#include "XGUI_OperationMgr.h"
#include "XGUI_Displayer.h"
#include "XGUI_PropertyPanel.h"
+#include "XGUI_ActionsMgr.h"
#include <ModuleBase_IModule.h>
#include <ModuleBase_ViewerPrs.h>
#include <AIS_Shape.hxx>
+#ifndef HAVE_SALOME
+#include "AppElements_Command.h"
+#endif
XGUI_ModuleConnector::XGUI_ModuleConnector(XGUI_Workshop* theWorkshop)
: ModuleBase_IWorkshop(theWorkshop),
void XGUI_ModuleConnector::updateCommandStatus()
{
myWorkshop->updateCommandStatus();
-}
\ No newline at end of file
+}
+
+QMainWindow* XGUI_ModuleConnector::desktop() const
+{
+ return myWorkshop->desktop();
+}
+
+
+std::shared_ptr<Config_FeatureMessage> XGUI_ModuleConnector::featureInfo(const QString& theId) const
+{
+#ifdef HAVE_SALOME
+ return myWorkshop->salomeConnector()->featureInfo(theId);
+#else
+ AppElements_Command* aAction =
+ dynamic_cast<AppElements_Command*>(myWorkshop->actionsMgr()->action(theId));
+ if (aAction)
+ return aAction->featureMessage();
+ return std::shared_ptr<Config_FeatureMessage>();
+#endif
+}
/// Update of commands status
virtual void updateCommandStatus();
+ /// Returns Information about feature defined in corresponded XML
+ /// \param theId - id of the feature
+ virtual std::shared_ptr<Config_FeatureMessage> featureInfo(const QString& theId) const;
+
+ /// Return application main window
+ virtual QMainWindow* desktop() const;
+
+
//! Returns workshop
XGUI_Workshop* workshop() const { return myWorkshop; }