//Widgets
const static char* WDG_DOUBLEVALUE = "doublevalue";
+const static char* WDG_BOOLVALUE = "boolvalue";
//Widget containers
const static char* WDG_INFO = "label";
const static char* WDG_GROUP = "groupbox";
const static char* WDG_TOOLBOX_BOX = "box";
const static char* WDG_SWITCH = "switch";
const static char* WDG_SWITCH_CASE = "case";
+const static char* WDG_SELECTOR = "selector";
//Specific widget containers
const static char* WDG_POINT_SELECTOR = "point_selector";
ConstructionPlugin.h
ConstructionPlugin_Plugin.h
ConstructionPlugin_Point.h
+ ConstructionPlugin_Extrusion.h
)
SET(PROJECT_SOURCES
ConstructionPlugin_Plugin.cpp
ConstructionPlugin_Point.cpp
+ ConstructionPlugin_Extrusion.cpp
)
ADD_DEFINITIONS(-DCONSTRUCTIONPLUGIN_EXPORTS ${BOOST_DEFINITIONS})
SET(XML_RESOURCES
plugin-Construction.xml
point_widget.xml
+ extrusion_widget.xml
)
INSTALL(TARGETS ConstructionPlugin DESTINATION plugins)
--- /dev/null
+// File: ConstructionPlugin_Extrusion.cpp
+// Created: 30 May 2014
+// Author: Vitaly SMETANNIKOV
+
+#include "ConstructionPlugin_Extrusion.h"
+#include <ModelAPI_PluginManager.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeBoolean.h>
+
+using namespace std;
+
+ConstructionPlugin_Extrusion::ConstructionPlugin_Extrusion()
+{
+}
+
+void ConstructionPlugin_Extrusion::initAttributes()
+{
+ data()->addAttribute(EXTRUSION_FACE, ModelAPI_AttributeReference::type());
+ data()->addAttribute(EXTRUSION_SIZE, ModelAPI_AttributeDouble::type());
+ data()->addAttribute(EXTRUSION_REVERCE, ModelAPI_AttributeBoolean::type());
+}
+
+// this is for debug only
+#include <iostream>
+void ConstructionPlugin_Extrusion::execute()
+{
+ // TODO: create a real shape for the point using OCC layer
+ //cout<<"X="<<data()->real(POINT_ATTR_X)->value()<<" Y="<<data()->real(POINT_ATTR_Y)->value()
+ // <<" Z="<<data()->real(POINT_ATTR_Z)->value()<<endl;
+}
--- /dev/null
+// File: ConstructionPlugin_Extrusion.h
+// Created: 30 May 2014
+// Author: Vitaly SMETANNIKOV
+
+#ifndef ConstructionPlugin_Extrusion_HeaderFile
+#define ConstructionPlugin_Extrusion_HeaderFile
+
+#include "ConstructionPlugin.h"
+#include <ModelAPI_Feature.h>
+
+/// attribute name of referenced face
+const std::string EXTRUSION_FACE = "extrusion_select_face";
+
+/// attribute name of extrusion size
+const std::string EXTRUSION_SIZE = "extrusion_size";
+
+/// attribute name of reverce direction
+const std::string EXTRUSION_REVERCE = "extrusion_reverse";
+
+
+class ConstructionPlugin_Extrusion: public ModelAPI_Feature
+{
+public:
+ /// Returns the kind of a feature
+ CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getKind()
+ { static std::string MY_KIND = "Extrusion"; return MY_KIND; }
+
+ /// Returns to which group in the document must be added feature
+ CONSTRUCTIONPLUGIN_EXPORT virtual const std::string& getGroup()
+ { static std::string MY_GROUP = "Construction"; return MY_GROUP; }
+
+ /// Creates a new part document if needed
+ CONSTRUCTIONPLUGIN_EXPORT virtual void execute();
+
+ /// Request for initialization of data model of the feature: adding all attributes
+ CONSTRUCTIONPLUGIN_EXPORT virtual void initAttributes();
+
+ /// Use plugin manager for features creation
+ ConstructionPlugin_Extrusion();
+};
+
+#endif
#include "ConstructionPlugin_Plugin.h"
#include "ConstructionPlugin_Point.h"
+#include "ConstructionPlugin_Extrusion.h"
+
#include <ModelAPI_PluginManager.h>
#include <ModelAPI_Document.h>
{
if (theFeatureID == "Point") {
return boost::shared_ptr<ModelAPI_Feature>(new ConstructionPlugin_Point);
+ } else if (theFeatureID == "Extrusion") {
+ return boost::shared_ptr<ModelAPI_Feature>(new ConstructionPlugin_Extrusion);
}
// feature of such kind is not found
return boost::shared_ptr<ModelAPI_Feature>();
--- /dev/null
+<source>
+ <selector id="extrusion_select_face"
+ label="Select a face"
+ icon=":icons/sketch.png"
+ tooltip="Select a face for extrusion"
+ />
+ <doublevalue id="extrusion_size" label="Size" min="0" step="1.0" default="10" icon=":icons/dimension_v.png" tooltip="Set size of extrusion"/>
+ <boolvalue id="extrusion_reverse" label="Reverse" default="false" tooltip="Reverse default direction"/>
+</source>
</feature>
<feature id="Axis" title="Axis" tooltip="Create a new axis" icon=":icons/axis.png" keysequence="" internal="true"/>
<feature id="Plane" title="Plane" tooltip="Create a new plane" icon=":icons/plane.png" keysequence="" internal="true"/>
+ <feature id="Extrusion" title="Extrusion" tooltip="Create a shape by extrusion of a contour" icon=":icons/extrusion.png">
+ <source path="extrusion_widget.xml"/>
+ </feature>
</group>
- </workbench>
+</workbench>
</plugin>
Model_AttributeReference.h
Model_AttributeRefAttr.h
Model_AttributeRefList.h
+ Model_AttributeBoolean.h
Model_Events.h
)
Model_AttributeReference.cpp
Model_AttributeRefAttr.cpp
Model_AttributeRefList.cpp
+ Model_AttributeBoolean.cpp
Model_Events.cpp
)
SET(PROJECT_LIBRARIES
--- /dev/null
+// File: Model_AttributeBoolean.cpp
+// Created: 2 june 2014
+// Author: Vitaly Smetannikov
+
+#include "Model_AttributeBoolean.h"
+#include "Model_Events.h"
+#include <Events_Loop.h>
+
+using namespace std;
+
+void Model_AttributeBoolean::setValue(bool theValue)
+{
+ if (myBool->Get() != theValue) {
+ myBool->Set(theValue? 1 : 0);
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
+ Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
+ Events_Loop::loop()->send(aMsg);
+ }
+}
+
+bool Model_AttributeBoolean::value()
+{
+ return (myBool->Get() == 1)? true : false;
+}
+
+Model_AttributeBoolean::Model_AttributeBoolean(TDF_Label& theLabel)
+{
+ // check the attribute could be already presented in this doc (after load document)
+ if (!theLabel.FindAttribute(TDataStd_Integer::GetID(), myBool)) {
+ // create attribute: not initialized by value yet, just zero
+ myBool = TDataStd_Integer::Set(theLabel, 0);
+ }
+}
--- /dev/null
+// File: Model_AttributeBoolean.h
+// Created: 2 june 2014
+// Author: Vitaly Smetannikov
+
+#ifndef Model_AttributeBoolean_HeaderFile
+#define Model_AttributeBoolean_HeaderFile
+
+#include "Model.h"
+#include "ModelAPI_AttributeBoolean.h"
+#include <TDataStd_Integer.hxx>
+#include <TDF_Label.hxx>
+
+/**\class Model_AttributeDouble
+ * \ingroup DataModel
+ * \brief Attribute that contains real value with double precision.
+ */
+
+class Model_AttributeBoolean : public ModelAPI_AttributeBoolean
+{
+ Handle_TDataStd_Integer myBool; ///< double is Real attribute
+public:
+ /// Defines the double value
+ MODEL_EXPORT virtual void setValue(bool theValue);
+
+ /// Returns the double value
+ MODEL_EXPORT virtual bool value();
+
+protected:
+ /// Initializes attibutes
+ Model_AttributeBoolean(TDF_Label& theLabel);
+
+ friend class Model_Data;
+};
+
+#endif
ModelAPI_AttributeReference.h
ModelAPI_AttributeRefAttr.h
ModelAPI_AttributeRefList.h
+ ModelAPI_AttributeBoolean.h
)
SET(PROJECT_SOURCES
--- /dev/null
+// File: ModelAPI_AttributeBoolean.h
+// Created: 2 june 2014
+// Author: Vitaly Smetannikov
+
+#ifndef ModelAPI_AttributeBoolean_HeaderFile
+#define ModelAPI_AttributeBoolean_HeaderFile
+
+#include "ModelAPI_Attribute.h"
+
+/**\class ModelAPI_AttributeBoolean
+ * \ingroup DataModel
+ * \brief Attribute that contains boolean value.
+ */
+
+class ModelAPI_AttributeBoolean : public ModelAPI_Attribute
+{
+public:
+ /// Defines the double value
+ MODELAPI_EXPORT virtual void setValue(bool theValue) = 0;
+
+ /// Returns the double value
+ MODELAPI_EXPORT virtual bool value() = 0;
+
+ /// Returns the type of this class of attributes
+ MODELAPI_EXPORT static std::string type() {return "Boolean";}
+
+ /// Returns the type of this class of attributes, not static method
+ MODELAPI_EXPORT virtual std::string attributeType() {return type();}
+
+ /// To virtually destroy the fields of successors
+ MODELAPI_EXPORT virtual ~ModelAPI_AttributeBoolean() {}
+
+protected:
+ /// Objects are created for features automatically
+ MODELAPI_EXPORT ModelAPI_AttributeBoolean() {}
+};
+
+#endif
#include <ModelAPI_Attribute.h>
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeBoolean.h>
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeRefList.h>
#include <QPixmap>
#include <QGroupBox>
#include <QToolBox>
+#include <QLineEdit>
+#include <QToolButton>
+#include <QCheckBox>
#ifdef _DEBUG
#include <QDebug>
QWidget* result = NULL;
if (theType == WDG_DOUBLEVALUE) {
result = doubleSpinBoxControl();
+
} else if (theType == WDG_INFO) {
result = labelControl(theParent);
- }
- else if (theType == WDG_POINT_SELECTOR) {
+
+ } else if (theType == WDG_SELECTOR) {
+ result = selectorControl(theParent);
+
+ } else if (theType == WDG_BOOLVALUE) {
+ result = booleanControl(theParent);
+
+ } else if (theType == WDG_POINT_SELECTOR) {
result = pointSelectorControl(theParent);
- }
- else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) {
+
+ } else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) {
result = createContainer(theType, theParent);
}
#ifdef _DEBUG
{
return QString::fromStdString(theStdString);
}
+
+
+QWidget* ModuleBase_WidgetFactory::selectorControl(QWidget* theParent)
+{
+ QWidget* aRes = new QWidget();
+ QHBoxLayout* aLayout = new QHBoxLayout(aRes);
+
+ aLayout->setContentsMargins(0, 0, 0, 0);
+ QString aLabelText = qs(myWidgetApi->widgetLabel());
+ QString aLabelIcon = qs(myWidgetApi->widgetIcon());
+ QLabel* aLabel = new QLabel(aLabelText, aRes);
+ aLabel->setPixmap(QPixmap(aLabelIcon));
+
+ aLayout->addWidget(aLabel);
+
+ QLineEdit* aTextLine = new QLineEdit(aRes);
+ aTextLine->setReadOnly(true);
+
+ aLayout->addWidget(aTextLine);
+
+ QToolButton* aActivateBtn = new QToolButton(aRes);
+ aActivateBtn->setIcon(QIcon(":icons/hand_point.png"));
+ aActivateBtn->setCheckable(true);
+
+ aLayout->addWidget(aActivateBtn);
+
+ return aRes;
+}
+
+
+QWidget* ModuleBase_WidgetFactory::booleanControl(QWidget* theParent)
+{
+ QString aText = qs(myWidgetApi->widgetLabel());
+ QString aToolTip = qs(myWidgetApi->widgetTooltip());
+ QString aDefault = qs(myWidgetApi->getProperty("default"));
+
+ QCheckBox* aRes = new QCheckBox(aText, theParent);
+ aRes->setToolTip(aToolTip);
+ aRes->setChecked(aDefault == "true");
+ return aRes;
+}
\ No newline at end of file
QWidget* doubleSpinBoxControl();
QWidget* pointSelectorControl(QWidget* theParent);
QWidget* createContainer(const std::string& theType, QWidget* theParent = NULL);
+ QWidget* selectorControl(QWidget* theParent);
+ QWidget* booleanControl(QWidget* theParent);
bool connectWidget(QObject*, const QString&);
QString qs(const std::string& theStdString) const;
<file>icons/import.png</file>
<file>icons/line.png</file>
<file>icons/sketch.png</file>
+ <file>icons/hand_point.png</file>
+ <file>icons/dimension_v.png</file>
</qresource>
</RCC>