#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_AttributeString.h>
#include <GeomAPI_Edge.h>
#include <GeomAlgoAPI_EdgeBuilder.h>
void ConstructionPlugin_Axis::initAttributes()
{
+ data()->addAttribute(ConstructionPlugin_Axis::METHOD(),
+ ModelAPI_AttributeString::type());
data()->addAttribute(ConstructionPlugin_Axis::POINT_FIRST(),
ModelAPI_AttributeSelection::type());
data()->addAttribute(ConstructionPlugin_Axis::POINT_SECOND(),
ModelAPI_AttributeSelection::type());
+ data()->addAttribute(ConstructionPlugin_Axis::CYLINDRICAL_FACE(),
+ ModelAPI_AttributeSelection::type());
}
void ConstructionPlugin_Axis::execute()
static const std::string CONSTRUCTION_AXIS_KIND("Axis");
return CONSTRUCTION_AXIS_KIND;
}
+
+ /// attribute name for first point
+ inline static const std::string& METHOD()
+ {
+ static const std::string METHOD_ATTR("creationMethod");
+ return METHOD_ATTR;
+ }
/// attribute name for first point
inline static const std::string& POINT_FIRST()
{
static const std::string POINT_ATTR_SECOND("secondPoint");
return POINT_ATTR_SECOND;
}
+ /// attribute name for second point
+ inline static const std::string& CYLINDRICAL_FACE()
+ {
+ static const std::string CYLINDRICAL_FACE_ATTR("cylindricalFace");
+ return CYLINDRICAL_FACE_ATTR;
+ }
/// default color for an axis
inline static const std::string& DEFAULT_COLOR()
{
<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
<source>
- <toolbox>
+ <toolbox id="creationMethod">
<box id="AxisByPointsCase" title="By two points">
<shape_selector id="firstPoint"
label="First point"
ModuleBase_IPrefMgr.h
ModuleBase_Preferences.h
ModuleBase_ActionInfo.h
+ ModuleBase_WidgetToolbox.h
)
SET(PROJECT_SOURCES
ModuleBase_WidgetLabel.cpp
ModuleBase_Preferences.cpp
ModuleBase_ActionInfo.cpp
+ ModuleBase_WidgetToolbox.cpp
)
SET(PROJECT_LIBRARIES
#include <ModuleBase_WidgetLineEdit.h>
#include <ModuleBase_WidgetMultiSelector.h>
#include <ModuleBase_WidgetLabel.h>
+#include <ModuleBase_WidgetToolbox.h>
#include <ModelAPI_Validator.h>
#include <ModelAPI_Session.h>
myWidgetApi->toChildWidget();
do {
QString aPageName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
+ QString aCaseId = qs(myWidgetApi->getProperty(_ID));
QWidget* aPage = new QWidget(aWidget);
createWidget(aPage);
ModuleBase_Tools::adjustMargins(aPage);
ModuleBase_WidgetSwitch* aSwitch = qobject_cast<ModuleBase_WidgetSwitch*>(aWidget);
aSwitch->addPage(aPage, aPageName);
} else if (aWdgType == WDG_TOOLBOX) {
- QToolBox* aToolbox = qobject_cast<QToolBox*>(aWidget);
- aToolbox->addItem(aPage, aPageName);
+ ModuleBase_WidgetToolbox* aToolbox = qobject_cast<ModuleBase_WidgetToolbox*>(aWidget);
+ aToolbox->addPage(aPage, aPageName, aCaseId);
}
-
} while (myWidgetApi->toNextWidget());
}
if (aWidget && !isStretchLayout) {
QWidget* ModuleBase_WidgetFactory::createContainer(const std::string& theType, QWidget* theParent)
{
- QWidget* result = NULL;
+ QWidget* aResult = NULL;
if (theType == WDG_GROUP || theType == WDG_CHECK_GROUP) {
QGroupBox* aGroupBox = new QGroupBox(theParent);
aGroupBox->setCheckable(theType == WDG_CHECK_GROUP);
- result = aGroupBox;
+ aResult = aGroupBox;
} else if (theType == WDG_TOOLBOX) {
- result = new QToolBox(theParent);
- // Dark-grey rounded tabs with button-like border #and bold font
- QString css = "QToolBox::tab{background-color:#c8c8c8;"
- "border-radius:5px;"
- "border:1px inset;"
- //"font-weight:700;"
- "border-color:#fff #505050 #505050 #fff;}";
- result->setStyleSheet(css);
- // default vertical size policy is preferred
- QSizePolicy aSizePolicy = result->sizePolicy();
- aSizePolicy.setVerticalPolicy(QSizePolicy::MinimumExpanding);
- result->setSizePolicy(aSizePolicy);
+ ModuleBase_WidgetToolbox* aWdg = new ModuleBase_WidgetToolbox(theParent, myWidgetApi, myParentId);
+ myModelWidgets.append(aWdg);
+ aResult = aWdg;
} else if (theType == WDG_SWITCH) {
- result = new ModuleBase_WidgetSwitch(theParent);
+ aResult = new ModuleBase_WidgetSwitch(theParent);
} else if (theType == WDG_TOOLBOX_BOX || theType == WDG_SWITCH_CASE) {
// Do nothing for "box" and "case"
- result = NULL;
+ aResult = NULL;
}
#ifdef _DEBUG
else {qDebug() << "ModuleBase_WidgetFactory::fillWidget: find bad container type";}
#endif
- return result;
+ return aResult;
}
QWidget* ModuleBase_WidgetFactory::labelControl(QWidget* theParent)
/// Create a widget of container type
/// \param theType a type
/// \param theParent a parent widget
- QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL);
+ QWidget* createContainer(const std::string& theType, QWidget* theParent);
/// Create label widget
/// \param theParent a parent widget
--- /dev/null
+/*
+ * ModuleBase_WidgetToolbox.cpp
+ *
+ * Created on: Feb 27, 2015
+ * Author: sbh
+ */
+
+#include <ModuleBase_WidgetToolbox.h>
+#include <ModuleBase_Tools.h>
+
+#include <ModelAPI_AttributeString.h>
+
+#include <QWidget>
+#include <QVBoxLayout>
+
+ModuleBase_WidgetToolbox::ModuleBase_WidgetToolbox(QWidget* theParent, const Config_WidgetAPI* theData,
+ const std::string& theParentId)
+: ModuleBase_ModelWidget(theParent, theData, theParentId)
+{
+ QVBoxLayout* aMainLayout = new QVBoxLayout(this);
+ ModuleBase_Tools::zeroMargins(aMainLayout);
+ myToolBox = new QToolBox(this);
+ // Dark-grey rounded tabs with button-like border #and bold font
+ QString css = "QToolBox::tab{background-color:#c8c8c8;"
+ "border-radius:5px;"
+ "border:1px inset;"
+ //"font-weight:700;"
+ "border-color:#fff #505050 #505050 #fff;}";
+ myToolBox->setStyleSheet(css);
+ // default vertical size policy is preferred
+ QSizePolicy aSizePolicy = myToolBox->sizePolicy();
+ aSizePolicy.setVerticalPolicy(QSizePolicy::MinimumExpanding);
+ myToolBox->setSizePolicy(aSizePolicy);
+ aMainLayout->addWidget(myToolBox);
+
+ connect(myToolBox, SIGNAL(currentChanged(int)), this, SLOT(onPageChanged()));
+}
+
+ModuleBase_WidgetToolbox::~ModuleBase_WidgetToolbox()
+{
+}
+
+int ModuleBase_WidgetToolbox::addPage(QWidget* theWidget,
+ const QString& theName, const QString& theCaseId)
+{
+ myCaseIds << theCaseId;
+ return myToolBox->addItem(theWidget, theName);
+}
+
+bool ModuleBase_WidgetToolbox::restoreValue()
+{
+ // A rare case when plugin was not loaded.
+ if(!myFeature)
+ return false;
+ DataPtr aData = myFeature->data();
+ AttributeStringPtr aStringAttr = aData->string(attributeID());
+ QString aCaseId = QString::fromStdString(aStringAttr->value());
+ int idx = myCaseIds.indexOf(aCaseId);
+ if (idx == -1)
+ return false;
+ bool isSignalsBlocked = myToolBox->blockSignals(true);
+ myToolBox->setCurrentIndex(idx);
+ myToolBox->blockSignals(isSignalsBlocked);
+ return true;
+}
+
+QList<QWidget*> ModuleBase_WidgetToolbox::getControls() const
+{
+ QList<QWidget*> aList;
+ aList << myToolBox;
+ return aList;
+}
+
+bool ModuleBase_WidgetToolbox::storeValueCustom() const
+{
+ // A rare case when plugin was not loaded.
+ if(!myFeature)
+ return false;
+ DataPtr aData = myFeature->data();
+ AttributeStringPtr aStringAttr = aData->string(attributeID());
+ QString aWidgetValue = myCaseIds.at(myToolBox->currentIndex());
+ aStringAttr->setValue(aWidgetValue.toStdString());
+ return true;
+}
+
+void ModuleBase_WidgetToolbox::onPageChanged()
+{
+ storeValue();
+}
--- /dev/null
+/*
+ * ModuleBase_WidgetToolbox.h
+ *
+ * Created on: Feb 27, 2015
+ * Author: sbh
+ */
+
+#ifndef MODULEBASE_WIDGETTOOLBOX_H_
+#define MODULEBASE_WIDGETTOOLBOX_H_
+
+#include <ModuleBase_ModelWidget.h>
+
+#include <QToolBox>
+
+class ModuleBase_WidgetToolbox : public ModuleBase_ModelWidget
+{
+ Q_OBJECT
+ public:
+ ModuleBase_WidgetToolbox(QWidget* theParent, const Config_WidgetAPI* theData,
+ const std::string& theParentId);
+ virtual ~ModuleBase_WidgetToolbox();
+
+ virtual bool restoreValue();
+ virtual QList<QWidget*> getControls() const;
+
+ int addPage(QWidget* theWidget, const QString& theName, const QString& theCaseId);
+
+ protected:
+ virtual bool storeValueCustom() const;
+
+ protected slots:
+ void onPageChanged();
+
+ private:
+ QToolBox* myToolBox;
+ QStringList myCaseIds;
+};
+
+#endif /* MODULEBASE_WIDGETTOOLBOX_H_ */
QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
bool isStoreValue = !theOperation->isEditOperation() &&
- !aWidget->getDefaultValue().empty() && !aWidget->isComputedDefault();
+ !aWidget->getDefaultValue().empty() &&
+ !aWidget->isComputedDefault();
aWidget->setFeature(theOperation->feature(), isStoreValue);
aWidget->enableFocusProcessing();
}