std::vector<int> stringToRGB(const std::string& theColor);
int stringToInteger(const std::string& theInt);
double stringToDouble(const std::string& theDouble);
+bool stringToBoolean(const std::string& theInt);
Config_Properties Config_PropManager::myProps;
return stringToDouble(aStr);
}
+bool Config_PropManager::boolean(const std::string& theSection,
+ const std::string& theName,
+ const std::string& theDefault)
+{
+ std::string aStr = string(theSection, theName, theDefault);
+ return stringToBoolean(aStr);
+}
+
std::vector<int> stringToRGB(const std::string& theColor)
{
std::vector<int> aRes(3);
char* p;
return strtod(theDouble.c_str(), &p);
}
+
+bool stringToBoolean(const std::string& theBoolean)
+{
+ return theBoolean == "true";
+}
CONFIG_EXPORT static double real(const std::string& theSection,
const std::string& theName,
const std::string& theDefault);
+ //! Returns boolean by given section and name
+ CONFIG_EXPORT static bool boolean(const std::string& theSection,
+ const std::string& theName,
+ const std::string& theDefault);
private:
CONFIG_EXPORT static Config_Properties myProps; ///< List of all stored properties
return result;
}
-bool Config_WidgetAPI::isContainerWidget() const
+bool Config_WidgetAPI::isGroupBoxWidget() const
{
return isNode(myCurrentNode, WDG_GROUP, WDG_CHECK_GROUP,
- NULL);
+ NULL);
}
bool Config_WidgetAPI::isPagedWidget() const
{
return isNode(myCurrentNode, WDG_TOOLBOX, WDG_SWITCH,
- NULL);
+ NULL);
}
std::string Config_WidgetAPI::getProperty(const char* thePropName) const
//! Returns name of widget's node (attribute)
std::string widgetType() const;
//! Returns true if widget has container type, which means it able to contain other widgets
- bool isContainerWidget() const;
+ bool isGroupBoxWidget() const;
//! Returns true if widget has page type;
//! Page is container widget with combo box control to switch between pages
bool isPagedWidget() const;
// register construction properties
Config_PropManager::registerProp("Visualization", "import_feature_color", "Imported feature color",
Config_Prop::Color, IMPORTED_FEATURE_COLOR);
+
+ // register random result color properties
+ Config_PropManager::registerProp("Visualization", "random_result_color", "Use random color for results",
+ Config_Prop::Bool, "true");
}
FeaturePtr ExchangePlugin_Plugin::createFeature(string theFeatureID)
if (nbSubResults == 1) {
itr.Initialize(theResult);
if (itr.More()) aResult = itr.Value();
+ } else {
+ /// MPV: store compound anyway: it may be Boolean operation that produces two solids from one
+ aResult = theResult;
}
}
return aResult;
Model_AttributeRefAttr.h
Model_AttributeRefList.h
Model_AttributeBoolean.h
+ Model_AttributeIntArray.h
Model_AttributeString.h
Model_AttributeInteger.h
Model_AttributeSelection.h
Model_AttributeRefAttr.cpp
Model_AttributeRefList.cpp
Model_AttributeBoolean.cpp
+ Model_AttributeIntArray.cpp
Model_AttributeString.cpp
Model_AttributeInteger.cpp
Model_AttributeSelection.cpp
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: Model_AttributeIntArray.cpp
+// Created: 6 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#include <Model_AttributeIntArray.h>
+#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Attribute.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_Object.h>
+
+#include <Standard_TypeDef.hxx>
+#include <TCollection_AsciiString.hxx>
+#include <TCollection_ExtendedString.hxx>
+#include <TDataStd_Integer.hxx>
+#include <TDataStd_Name.hxx>
+
+#include <string>
+
+int Model_AttributeIntArray::size()
+{
+ return myArray.IsNull() ? 0 : myArray->Length();
+}
+
+void Model_AttributeIntArray::setSize(const int theSize)
+{
+ if (myArray.IsNull()) { // create array if it is not done yet
+ if (theSize != 0) { // if size is zero, nothing to do (null array means there is no array)
+ myArray = TDataStd_IntegerArray::Set(myLab, 0, theSize);
+ owner()->data()->sendAttributeUpdated(this);
+ }
+ } else { // reset the old array
+ if (theSize) {
+ if (theSize != myArray->Length()) { // old data is not keept, a new array is created
+ Handle(TColStd_HArray1OfInteger) aNewArray = new TColStd_HArray1OfInteger(0, theSize - 1);
+ myArray->ChangeArray(aNewArray);
+ owner()->data()->sendAttributeUpdated(this);
+ }
+ } else { // size is zero => array must be erased
+ if (!myArray.IsNull()) {
+ myArray.Nullify();
+ myLab.ForgetAttribute(TDataStd_IntegerArray::GetID());
+ owner()->data()->sendAttributeUpdated(this);
+ }
+ }
+ }
+}
+
+void Model_AttributeIntArray::setValue(const int theIndex,
+ const int theValue)
+{
+ if (myArray->Value(theIndex) != theValue) {
+ myArray->SetValue(theIndex, theValue);
+ owner()->data()->sendAttributeUpdated(this);
+ }
+}
+
+int Model_AttributeIntArray::value(const int theIndex)
+{
+ return myArray->Value(theIndex);
+}
+
+Model_AttributeIntArray::Model_AttributeIntArray(TDF_Label& theLabel)
+{
+ myLab = theLabel;
+ // check the attribute could be already presented in this doc (after load document)
+ myIsInitialized =
+ myLab.FindAttribute(TDataStd_IntegerArray::GetID(), myArray) == Standard_True;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: Model_AttributeIntArray.h
+// Created: 6 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef MODEL_ATTRIBUTEINTARRAY_H_
+#define MODEL_ATTRIBUTEINTARRAY_H_
+
+#include <Model.h>
+#include <ModelAPI_AttributeIntArray.h>
+
+#include <TDF_Label.hxx>
+#include <TDataStd_IntegerArray.hxx>
+
+#include <string>
+
+/**\class Model_AttributeIntArray
+ * \ingroup DataModel
+ * \brief API for the attribute that contains several integers in the array inside.
+ * Used for RGB color storage for an example. By default size is one, zero-based.
+ * Represented as array in OCCT. Empty array means that this attribute does not exists.
+ */
+
+class Model_AttributeIntArray : public ModelAPI_AttributeIntArray
+{
+ /// The OCCT array that keeps all values.
+ Handle_TDataStd_IntegerArray myArray;
+ /// Stores the label as a field to set array if size is not null (null array is buggy in OCAF)
+ TDF_Label myLab;
+ public:
+
+ /// Returns the size of the array (zero means that it is empty)
+ MODEL_EXPORT virtual int size();
+
+ /// Sets the new size of the array. The previous data is erased.
+ MODEL_EXPORT virtual void setSize(const int theSize);
+
+ /// Defines the value of the array by index [0; size-1]
+ MODEL_EXPORT virtual void setValue(const int theIndex,
+ const int theValue);
+
+ /// Returns the value by the index
+ MODEL_EXPORT virtual int value(const int theIndex);
+
+
+ protected:
+ /// Initializes attibutes
+ Model_AttributeIntArray(TDF_Label& theLabel);
+
+ friend class Model_Data;
+};
+
+#endif
#include <Model_AttributeString.h>
#include <Model_AttributeSelection.h>
#include <Model_AttributeSelectionList.h>
+#include <Model_AttributeIntArray.h>
#include <Model_Events.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Result.h>
anAttr = new Model_AttributeRefAttr(anAttrLab);
} else if (theAttrType == ModelAPI_AttributeRefList::type()) {
anAttr = new Model_AttributeRefList(anAttrLab);
+ } else if (theAttrType == ModelAPI_AttributeIntArray::type()) {
+ anAttr = new Model_AttributeIntArray(anAttrLab);
}
// create also GeomData attributes here because only here the OCAF strucure is known
else if (theAttrType == GeomData_Point::type()) {
GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeSelectionList, selectionList);
GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefAttr, refattr);
GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeRefList, reflist);
+GET_ATTRIBUTE_BY_ID(ModelAPI_AttributeIntArray, intArray);
std::shared_ptr<ModelAPI_Attribute> Model_Data::attribute(const std::string& theID)
{
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeIntArray.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_Object.h>
/// Returns the attribute that contains real value with double precision
MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeString>
string(const std::string& theID);
+ /// Returns the attribute that contains integer values array
+ MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeIntArray>
+ intArray(const std::string& theID);
+
/// Returns the generic attribute by identifier
/// \param theID identifier of the attribute
MODEL_EXPORT virtual std::shared_ptr<ModelAPI_Attribute> attribute(const std::string& theID);
FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
if (aFeature) {
setUniqueName(aFeature); // must be before "initAttributes" because duplicate part uses name
- aFeature->initAttributes();
}
+ theObj->initAttributes();
}
void Model_Document::synchronizeFeatures(const bool theMarkUpdated, const bool theUpdateReferences)
#include <Model_ResultBody.h>
#include <Model_Data.h>
#include <Model_Document.h>
+#include <ModelAPI_AttributeIntArray.h>
#include <TNaming_Builder.hxx>
#include <TNaming_NamedShape.hxx>
#include <TDataStd_Name.hxx>
#include <BRep_Tool.hxx>
#include <GeomAPI_Shape.h>
#include <GeomAlgoAPI_MakeShape.h>
+#include <Config_PropManager.h>
// DEB
//#include <TCollection_AsciiString.hxx>
//#include <TDF_Tool.hxx>
setIsConcealed(false);
}
+void Model_ResultBody::initAttributes()
+{
+ // append the color attribute
+ DataPtr aData = data();
+ aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::type());
+ AttributeIntArrayPtr aColorAttr = aData->intArray(COLOR_ID());
+ std::vector<int> aRGB;
+ aRGB = Config_PropManager::color("Visualization", "result_body_color", DEFAULT_COLOR());
+ aColorAttr->setSize(3);
+ aColorAttr->setValue(0, aRGB[0]);
+ aColorAttr->setValue(1, aRGB[1]);
+ aColorAttr->setValue(2, aRGB[2]);
+}
+
void Model_ResultBody::store(const std::shared_ptr<GeomAPI_Shape>& theShape)
{
std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
/// label; index in vector corresponds to the label tag
std::vector<TNaming_Builder*> myBuilders;
public:
+ /// default color for a result body
+ inline static const std::string& DEFAULT_COLOR()
+ {
+ static const std::string RESULT_BODY_COLOR("#E0A01B");
+ return RESULT_BODY_COLOR;
+ }
+
+ /// Request for initialization of data model of the result: adding all attributes
+ virtual void initAttributes();
+
/// Stores the shape (called by the execution method).
MODEL_EXPORT virtual void store(const std::shared_ptr<GeomAPI_Shape>& theShape);
#include <Model_ResultConstruction.h>
+#include <ModelAPI_AttributeIntArray.h>
+#include <Config_PropManager.h>
+
+void Model_ResultConstruction::initAttributes()
+{
+ // append the color attribute
+ DataPtr aData = data();
+ aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::type());
+ AttributeIntArrayPtr aColorAttr = aData->intArray(COLOR_ID());
+ std::vector<int> aRGB;
+ aRGB = Config_PropManager::color("Visualization", "result_construction_color", DEFAULT_COLOR());
+ aColorAttr->setSize(3);
+ aColorAttr->setValue(0, aRGB[0]);
+ aColorAttr->setValue(1, aRGB[1]);
+ aColorAttr->setValue(2, aRGB[2]);
+}
+
void Model_ResultConstruction::setShape(std::shared_ptr<GeomAPI_Shape> theShape)
{
myShape = theShape;
std::shared_ptr<GeomAPI_Shape> myShape; ///< shape of this result created "on the fly"
bool myIsInHistory;
public:
+ /// default color for a result construction
+ inline static const std::string& DEFAULT_COLOR()
+ {
+ static const std::string RESULT_CONSTRUCTION_COLOR("#000000");
+ return RESULT_CONSTRUCTION_COLOR;
+ }
+
+ /// Request for initialization of data model of the result: adding all attributes
+ virtual void initAttributes();
+
/// By default object is displayed in the object browser.
MODEL_EXPORT virtual bool isInHistory()
{
#include <Model_ResultGroup.h>
#include <ModelAPI_AttributeSelectionList.h>
+#include <ModelAPI_AttributeIntArray.h>
+
#include <GeomAlgoAPI_CompoundBuilder.h>
+#include <Config_PropManager.h>
+
Model_ResultGroup::Model_ResultGroup(std::shared_ptr<ModelAPI_Data> theOwnerData)
{
setIsConcealed(false);
myOwnerData = theOwnerData;
}
+void Model_ResultGroup::initAttributes()
+{
+ // append the color attribute
+ DataPtr aData = data();
+ aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::type());
+ AttributeIntArrayPtr aColorAttr = aData->intArray(COLOR_ID());
+ std::vector<int> aRGB;
+ aRGB = Config_PropManager::color("Visualization", "result_group_color", DEFAULT_COLOR());
+ aColorAttr->setSize(3);
+ aColorAttr->setValue(0, aRGB[0]);
+ aColorAttr->setValue(1, aRGB[1]);
+ aColorAttr->setValue(2, aRGB[2]);
+}
+
std::shared_ptr<GeomAPI_Shape> Model_ResultGroup::shape()
{
std::shared_ptr<GeomAPI_Shape> aResult;
{
std::shared_ptr<ModelAPI_Data> myOwnerData; ///< data of owner of this result
public:
+ /// default color for a result body
+ inline static const std::string& DEFAULT_COLOR()
+ {
+ static const std::string RESULT_GROUP_COLOR("#E0A01B");
+ return RESULT_GROUP_COLOR;
+ }
+ /// Request for initialization of data model of the result: adding all attributes
+ virtual void initAttributes();
+
/// Returns the compound of selected entities
MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> shape();
ModelAPI.h
ModelAPI_Attribute.h
ModelAPI_AttributeBoolean.h
+ ModelAPI_AttributeIntArray.h
ModelAPI_AttributeDocRef.h
ModelAPI_AttributeDouble.h
ModelAPI_AttributeInteger.h
SET(PROJECT_SOURCES
ModelAPI_Attribute.cpp
ModelAPI_AttributeBoolean.cpp
+ ModelAPI_AttributeIntArray.cpp
ModelAPI_AttributeDocRef.cpp
ModelAPI_AttributeDouble.cpp
ModelAPI_AttributeInteger.cpp
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModelAPI_AttributeIntArray.cpp
+// Created: 6 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#include <ModelAPI_AttributeIntArray.h>
+
+
+std::string ModelAPI_AttributeIntArray::attributeType()
+{
+ return type();
+}
+
+/// To virtually destroy the fields of successors
+ModelAPI_AttributeIntArray::~ModelAPI_AttributeIntArray()
+{
+}
+
+ModelAPI_AttributeIntArray::ModelAPI_AttributeIntArray()
+{
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: ModelAPI_AttributeIntArray.h
+// Created: 6 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef ModelAPI_AttributeIntArray_H_
+#define ModelAPI_AttributeIntArray_H_
+
+#include <ModelAPI.h>
+#include <ModelAPI_Attribute.h>
+
+#include <string>
+
+
+/**\class ModelAPI_AttributeIntArray
+ * \ingroup DataModel
+ * \brief API for the attribute that contains several integers in the array inside.
+ * Used for RGB color storage for an example. By default size is one, zero-based.
+ */
+
+class ModelAPI_AttributeIntArray : public ModelAPI_Attribute
+{
+ public:
+
+ /// Returns the size of the array (zero means that it is empty)
+ MODELAPI_EXPORT virtual int size() = 0;
+
+ /// Sets the new size of the array. The previous data is erased.
+ MODELAPI_EXPORT virtual void setSize(const int theSize) = 0;
+
+ /// Defines the value of the array by index [0; size-1]
+ MODELAPI_EXPORT virtual void setValue(const int theIndex,
+ const int theValue) = 0;
+
+ /// Returns the value by the index
+ MODELAPI_EXPORT virtual int value(const int theIndex) = 0;
+
+ /// Returns the type of this class of attributes
+ MODELAPI_EXPORT static std::string type()
+ {
+ return "IntArray";
+ }
+
+ /// Returns the type of this class of attributes, not static method
+ MODELAPI_EXPORT virtual std::string attributeType();
+
+ /// To virtually destroy the fields of successors
+ MODELAPI_EXPORT virtual ~ModelAPI_AttributeIntArray();
+
+ protected:
+ /// Objects are created for features automatically
+ MODELAPI_EXPORT ModelAPI_AttributeIntArray();
+};
+
+//! Pointer on double attribute
+typedef std::shared_ptr<ModelAPI_AttributeIntArray> AttributeIntArrayPtr;
+
+#endif
class ModelAPI_Feature;
class ModelAPI_AttributeSelection;
class ModelAPI_AttributeSelectionList;
+class ModelAPI_AttributeIntArray;
class ModelAPI_Object;
class GeomAPI_Shape;
virtual std::shared_ptr<ModelAPI_AttributeBoolean> boolean(const std::string& theID) = 0;
/// Returns the attribute that contains boolean value
virtual std::shared_ptr<ModelAPI_AttributeString> string(const std::string& theID) = 0;
+ /// Returns the attribute that contains integer values array
+ virtual std::shared_ptr<ModelAPI_AttributeIntArray> intArray(const std::string& theID) = 0;
/// Returns the generic attribute by identifier
/// \param theID identifier of the attribute
return group();
}
- /// Request for initialization of data model of the feature: adding all attributes
- virtual void initAttributes() = 0;
-
/// Computes or recomputes the results
virtual void execute() = 0;
/// Returns the group identifier of this object
virtual std::string groupName() = 0;
+ /// Request for initialization of data model of the object: adding all attributes
+ virtual void initAttributes() = 0;
+
/// Called on change of any argument-attribute of this object
/// \param theID identifier of changed attribute
// MODELAPI_EXPORT
{
bool myIsConcealed; ///< the result is concealed from the data tree (referenced by other objects)
public:
- /// Returns true if the result is concealed from the data tree (referenced by other objects)
+
+ /// Reference to the color of the result
+ inline static const std::string& COLOR_ID()
+ {
+ static const std::string MY_COLOR_ID("Color");
+ return MY_COLOR_ID;
+ }
+
+ /// Returns true if the result is concealed from the data tree (referenced by other objects)
inline bool isConcealed()
{
return myIsConcealed;
myIsConcealed = theValue;
}
+ /// Request for initialization of data model of the result: adding all attributes
+ virtual void initAttributes() {};
+
/// To virtually destroy the fields of successors
MODELAPI_EXPORT virtual ~ModelAPI_Result();
ModuleBase_Preferences.h
ModuleBase_ActionInfo.h
ModuleBase_WidgetToolbox.h
+ ModuleBase_PageBase.h
+ ModuleBase_PageWidget.h
+ ModuleBase_PageGroupBox.h
)
SET(PROJECT_SOURCES
ModuleBase_Preferences.cpp
ModuleBase_ActionInfo.cpp
ModuleBase_WidgetToolbox.cpp
+ ModuleBase_PageBase.cpp
+ ModuleBase_PageWidget.cpp
+ ModuleBase_PageGroupBox.cpp
)
SET(PROJECT_LIBRARIES
/// \param theWidgetApi the widget configuation. The attribute of the model widget is obtained from\r
/// \param theParentId is Id of a parent of the current attribute\r
/// \param theModelWidgets list of widget objects\r
- virtual QWidget* createWidgetByType(const std::string& theType, QWidget* theParent,\r
- Config_WidgetAPI* theWidgetApi, std::string theParentId,\r
- QList<ModuleBase_ModelWidget*>& theModelWidgets)\r
+ virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,\r
+ Config_WidgetAPI* theWidgetApi, std::string theParentId)\r
{\r
return 0;\r
}\r
--- /dev/null
+/*
+ * ModuleBase_PageBase.cpp
+ *
+ * Created on: Mar 4, 2015
+ * Author: sbh
+ */
+
+#include <ModuleBase_PageBase.h>
+#include <ModuleBase_ModelWidget.h>
+
+#include <QLayout>
+
+class QWidget;
+
+ModuleBase_PageBase::ModuleBase_PageBase()
+{
+
+}
+
+ModuleBase_PageBase::~ModuleBase_PageBase()
+{
+
+}
+
+QWidget* ModuleBase_PageBase::pageWidget()
+{
+ return dynamic_cast<QWidget*>(this);
+}
+
+void ModuleBase_PageBase::addModelWidget(ModuleBase_ModelWidget* theWidget)
+{
+ placeModelWidget(theWidget);
+ myWidgetList.append(theWidget);
+}
+
+void ModuleBase_PageBase::addPageWidget(ModuleBase_PageBase* thePage)
+{
+ placePageWidget(thePage);
+}
+
+void ModuleBase_PageBase::clearPage()
+{
+ QLayoutItem *aChild;
+ while ((aChild = pageLayout()->takeAt(0)) != 0) {
+ if(aChild->widget()) {
+ aChild->widget()->deleteLater();
+ } else {
+ delete aChild;
+ }
+ }
+ myWidgetList.clear();
+}
+
+
+void ModuleBase_PageBase::takeFocus()
+{
+ if(myWidgetList.isEmpty())
+ return;
+
+ myWidgetList.first()->focusTo();
+}
+
+QList<ModuleBase_ModelWidget*> ModuleBase_PageBase::modelWidgets()
+{
+ return myWidgetList;
+}
+
+void ModuleBase_PageBase::alignToTop()
+{
+ bool hasExpanding = false;
+ QList<QWidget *> aListToCheck;
+ ModuleBase_ModelWidget* aModelWidget;
+ foreach(aModelWidget, myWidgetList) {
+ aListToCheck << aModelWidget->getControls();
+ }
+ foreach(QWidget* eachWidget, aListToCheck) {
+ QSizePolicy::Policy aVPolicy = eachWidget->sizePolicy().verticalPolicy();
+ if(aVPolicy & QSizePolicy::ExpandFlag) {
+ hasExpanding = true;
+ break;
+ }
+ }
+ if(!hasExpanding) {
+ addPageStretch();
+ }
+}
--- /dev/null
+/*
+ * ModuleBase_PageBase.h
+ *
+ * Created on: Mar 4, 2015
+ * Author: sbh
+ */
+
+#ifndef MODULEBASE_PAGEBASE_H_
+#define MODULEBASE_PAGEBASE_H_
+
+#include <ModuleBase.h>
+#include <ModuleBase_Tools.h>
+
+class ModuleBase_ModelWidget;
+class QLayout;
+class QWidget;
+
+/*!
+ * Represent a property panel's list of ModuleBase_ModelWidgets.
+ */
+class MODULEBASE_EXPORT ModuleBase_PageBase
+{
+ public:
+ ModuleBase_PageBase();
+ virtual ~ModuleBase_PageBase();
+ QWidget* pageWidget();
+
+ void addModelWidget(ModuleBase_ModelWidget* theWidget);
+ void addPageWidget(ModuleBase_PageBase* theWidget);
+
+ void clearPage();
+ void takeFocus();
+ QList<ModuleBase_ModelWidget*> modelWidgets();
+ void alignToTop();
+
+ protected:
+ virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget) = 0;
+ virtual void placePageWidget(ModuleBase_PageBase* theWidget) = 0;
+ virtual QLayout* pageLayout() = 0;
+ virtual void addPageStretch() = 0;
+
+ private:
+ QList<ModuleBase_ModelWidget*> myWidgetList;
+
+};
+
+#endif /* MODULEBASE_PAGEBASE_H_ */
--- /dev/null
+/*
+ * ModuleBase_PageGroupBox.cpp
+ *
+ * Created on: Mar 4, 2015
+ * Author: sbh
+ */
+
+#include <ModuleBase_PageGroupBox.h>
+#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_Tools.h>
+
+#include <QGridLayout>
+
+ModuleBase_PageGroupBox::ModuleBase_PageGroupBox(QWidget* theParent)
+: QGroupBox(theParent)
+{
+ myMainLayout = new QGridLayout(this);
+ ModuleBase_Tools::adjustMargins(myMainLayout);
+ setLayout(myMainLayout);
+}
+
+ModuleBase_PageGroupBox::~ModuleBase_PageGroupBox()
+{
+}
+
+void ModuleBase_PageGroupBox::addPageStretch()
+{
+}
+
+void ModuleBase_PageGroupBox::placeModelWidget(ModuleBase_ModelWidget* theWidget)
+{
+ const int kCol = 0;
+ const int kRow = myMainLayout->count();
+ myMainLayout->addWidget(theWidget, kRow, kCol, Qt::AlignTop | Qt::AlignLeft);
+}
+
+void ModuleBase_PageGroupBox::placePageWidget(ModuleBase_PageBase* theWidget)
+{
+ QWidget* aWidget = dynamic_cast<QWidget*>(theWidget);
+ if (!aWidget) {
+ #ifdef _DEBUG
+ std::cout << "ModuleBase_PageGroupBox::placePageWidget: can not cast page" << std::endl;
+ #endif
+ return;
+ }
+ const int kCol = 0;
+ const int kRow = myMainLayout->count();
+ myMainLayout->addWidget(aWidget, kRow, kCol, Qt::AlignTop | Qt::AlignLeft);
+}
+
+QLayout* ModuleBase_PageGroupBox::pageLayout()
+{
+ return myMainLayout;
+}
--- /dev/null
+/*
+ * ModuleBase_PageGroupBox.h
+ *
+ * Created on: Mar 4, 2015
+ * Author: sbh
+ */
+
+#ifndef MODULEBASE_PAGEGROUPBOX_H_
+#define MODULEBASE_PAGEGROUPBOX_H_
+
+#include <ModuleBase.h>
+#include <ModuleBase_PageBase.h>
+
+#include <QGroupBox>
+#include <QList>
+
+class ModuleBase_ModelWidget;
+class QGridLayout;
+
+
+/*!
+ * Represent a property panel's list of ModuleBase_ModelWidgets.
+ */
+class MODULEBASE_EXPORT ModuleBase_PageGroupBox : public QGroupBox, public ModuleBase_PageBase
+{
+ public:
+ explicit ModuleBase_PageGroupBox(QWidget* theParent = 0);
+ virtual ~ModuleBase_PageGroupBox();
+
+ protected:
+ virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget);
+ virtual void placePageWidget(ModuleBase_PageBase* theWidget);
+ virtual QLayout* pageLayout();
+ virtual void addPageStretch();
+
+ private:
+ QGridLayout* myMainLayout;
+};
+
+#endif /* MODULEBASE_PAGEGROUPBOX_H_ */
--- /dev/null
+/*
+ * ModuleBase_PageWidget.cpp
+ *
+ * Created on: Mar 4, 2015
+ * Author: sbh
+ */
+
+#include <ModuleBase_PageWidget.h>
+#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_Tools.h>
+
+#include <QGridLayout>
+
+ModuleBase_PageWidget::ModuleBase_PageWidget(QWidget* theParent)
+: QFrame(theParent)
+{
+ myMainLayout = new QGridLayout(this);
+ ModuleBase_Tools::adjustMargins(myMainLayout);
+ setLayout(myMainLayout);
+}
+
+ModuleBase_PageWidget::~ModuleBase_PageWidget()
+{
+}
+
+void ModuleBase_PageWidget::addPageStretch()
+{
+ myMainLayout->setRowStretch(myMainLayout->rowCount(), 1);
+}
+
+void ModuleBase_PageWidget::placeModelWidget(ModuleBase_ModelWidget* theWidget)
+{
+ const int kCol = 0;
+ const int kRow = myMainLayout->count();
+ myMainLayout->addWidget(theWidget, kRow, kCol);
+}
+
+void ModuleBase_PageWidget::placePageWidget(ModuleBase_PageBase* theWidget)
+{
+ QWidget* aWidget = dynamic_cast<QWidget*>(theWidget);
+ if (!aWidget) {
+ #ifdef _DEBUG
+ std::cout << "ModuleBase_PageWidget::placePageWidget: can not cast page" << std::endl;
+ #endif
+ return;
+ }
+ const int kCol = 0;
+ const int kRow = myMainLayout->count();
+ myMainLayout->addWidget(aWidget, kRow, kCol);//, Qt::AlignTop | Qt::AlignLeft);
+}
+
+QLayout* ModuleBase_PageWidget::pageLayout()
+{
+ return myMainLayout;
+}
--- /dev/null
+/*
+ * ModuleBase_PageWidget.h
+ *
+ * Created on: Mar 4, 2015
+ * Author: sbh
+ */
+
+#ifndef MODULEBASE_PAGEWIDGET_H_
+#define MODULEBASE_PAGEWIDGET_H_
+
+#include <ModuleBase.h>
+#include <ModuleBase_PageBase.h>
+
+#include <QFrame>
+#include <QList>
+
+class ModuleBase_ModelWidget;
+class QGridLayout;
+
+/*!
+ * Represent a property panel's list of ModuleBase_ModelWidgets.
+ */
+class MODULEBASE_EXPORT ModuleBase_PageWidget : public QFrame, public ModuleBase_PageBase
+{
+ public:
+ explicit ModuleBase_PageWidget(QWidget* theParent = 0);
+ virtual ~ModuleBase_PageWidget();
+
+ protected:
+ virtual void placeModelWidget(ModuleBase_ModelWidget* theWidget);
+ virtual void placePageWidget(ModuleBase_PageBase* theWidget);
+ virtual QLayout* pageLayout();
+ virtual void addPageStretch();
+
+ private:
+ QGridLayout* myMainLayout;
+};
+
+#endif /* MODULEBASE_PAGEWIDGET_H_ */
#include "ModuleBase_Preferences.h"
//#include "ModuleBase_Constants.h"
+#include <Model_ResultBody.h>
+#include <Model_ResultGroup.h>
+#include <Model_ResultConstruction.h>
+
#include <Config_PropManager.h>
#include <SUIT_ResourceMgr.h>
myPreferences->setItemProperty("texture_stretch_enabled", true, bgId);
myPreferences->setItemProperty("custom_enabled", false, bgId);
myPreferences->setItemProperty("image_formats", aImgFiles, bgId);
+
+ Config_PropManager::registerProp("Visualization", "result_body_color", "Body color",
+ Config_Prop::Color, Model_ResultBody::DEFAULT_COLOR());
+ Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
+ Config_Prop::Color, Model_ResultGroup::DEFAULT_COLOR());
+ Config_PropManager::registerProp("Visualization", "result_construction_color", "Construction color",
+ Config_Prop::Color, Model_ResultConstruction::DEFAULT_COLOR());
}
void ModuleBase_PreferencesDlg::createMenuPage(int thePageId)
#include <ModuleBase_WidgetMultiSelector.h>
#include <ModuleBase_WidgetLabel.h>
#include <ModuleBase_WidgetToolbox.h>
+#include <ModuleBase_PageBase.h>
+#include <ModuleBase_PageGroupBox.h>
+#include <ModuleBase_PageWidget.h>
#include <ModelAPI_Validator.h>
#include <ModelAPI_Session.h>
delete myWidgetApi;
}
-void ModuleBase_WidgetFactory::createWidget(QWidget* theParent)
+void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage)
{
myParentId = myWidgetApi->widgetId();
if (!myWidgetApi->toChildWidget())
return;
- QVBoxLayout* aWidgetLay = new QVBoxLayout(theParent);
- bool isStretchLayout = false;
do { //Iterate over each node
std::string aWdgType = myWidgetApi->widgetType();
- //Create a widget (doublevalue, groupbox, toolbox, etc.
- QWidget* aWidget = createWidgetByType(aWdgType, theParent);
- if (aWidget) {
- if (!myWidgetApi->getBooleanAttribute(ATTR_INTERNAL, false)) {
- aWidgetLay->addWidget(aWidget);
- } else {
- aWidget->setVisible(false);
- }
- }
- if (myWidgetApi->isContainerWidget()) {
+ // Create PageGroup TODO: extract
+ if (myWidgetApi->isGroupBoxWidget()) {
//if current widget is groupbox (container) process it's children recursively
QString aGroupName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
- createWidget(aWidget);
- ModuleBase_Tools::adjustMargins(aWidget);
- QGroupBox* aGrBox = qobject_cast<QGroupBox*>(aWidget);
- aGrBox->setTitle(aGroupName);
- }
- if (myWidgetApi->isPagedWidget()) {
- //If current widget is toolbox or switch-casebox then fetch all
- //it's pages recursively and setup into the widget.
- 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);
- if (aWdgType == WDG_SWITCH) {
- ModuleBase_WidgetSwitch* aSwitch = qobject_cast<ModuleBase_WidgetSwitch*>(aWidget);
- aSwitch->addPage(aPage, aPageName);
- } else if (aWdgType == WDG_TOOLBOX) {
- ModuleBase_WidgetToolbox* aToolbox = qobject_cast<ModuleBase_WidgetToolbox*>(aWidget);
- aToolbox->addPage(aPage, aPageName, aCaseId);
+ ModuleBase_PageGroupBox* aPage = new ModuleBase_PageGroupBox(thePage->pageWidget());
+ aPage->setTitle(aGroupName);
+ createWidget(aPage);
+ thePage->addPageWidget(aPage);
+ } else {
+ // Create a ModelWidget
+ ModuleBase_ModelWidget* aWidget = createWidgetByType(aWdgType, thePage->pageWidget());
+ if (aWidget) {
+ if (!myWidgetApi->getBooleanAttribute(ATTR_INTERNAL, false)) {
+ thePage->addModelWidget(aWidget);
+ } else {
+ aWidget->setVisible(false);
}
- } while (myWidgetApi->toNextWidget());
- }
- if (aWidget && !isStretchLayout) {
- isStretchLayout = !hasExpandingControls(aWidget);
+ }
+ // Create PagedContainer TODO: extract
+ if (myWidgetApi->isPagedWidget()) {
+ //If current widget is toolbox or switch-casebox then fetch all
+ //it's pages recursively and setup into the widget.
+ myWidgetApi->toChildWidget();
+ do {
+ QString aPageName = qs(myWidgetApi->getProperty(CONTAINER_PAGE_NAME));
+ QString aCaseId = qs(myWidgetApi->getProperty(_ID));
+ ModuleBase_PageBase* aPage = new ModuleBase_PageWidget(aWidget);
+ createWidget(aPage);
+ QWidget* aCasePageWidget = dynamic_cast<QWidget*>(aPage);
+ if (aWdgType == WDG_SWITCH) {
+ ModuleBase_WidgetSwitch* aSwitch = qobject_cast<ModuleBase_WidgetSwitch*>(aWidget);
+ aSwitch->addPage(aCasePageWidget, aPageName);
+ } else if (aWdgType == WDG_TOOLBOX) {
+ ModuleBase_WidgetToolbox* aToolbox = qobject_cast<ModuleBase_WidgetToolbox*>(aWidget);
+ aToolbox->addPage(aPage, aPageName, aCaseId);
+ }
+ } while (myWidgetApi->toNextWidget());
+ }
}
} while (myWidgetApi->toNextWidget());
- if (isStretchLayout) {
- aWidgetLay->addStretch(1);
- }
- theParent->setLayout(aWidgetLay);
-}
-bool ModuleBase_WidgetFactory::hasExpandingControls(QWidget* theParent)
-{
- bool result = false;
- QList<QWidget *> aListToCheck;
- aListToCheck << theParent;
- ModuleBase_ModelWidget* aModelWidget = qobject_cast<ModuleBase_ModelWidget*>(theParent);
- if(aModelWidget) {
- aListToCheck << aModelWidget->getControls();
- }
- foreach(QWidget* eachWidget, aListToCheck) {
- QSizePolicy::Policy aVPolicy = eachWidget->sizePolicy().verticalPolicy();
- if(aVPolicy & QSizePolicy::ExpandFlag) {
- result = true;
- }
- }
- return result;
+ thePage->alignToTop();
}
-QWidget* ModuleBase_WidgetFactory::createWidgetByType(const std::string& theType,
- QWidget* theParent)
+ModuleBase_ModelWidget* ModuleBase_WidgetFactory
+::createWidgetByType(const std::string& theType, QWidget* theParent)
{
- QWidget* result = NULL;
- if (theType == WDG_DOUBLEVALUE) {
- result = doubleSpinBoxControl(theParent);
+ ModuleBase_ModelWidget* result = NULL;
+
+ if (theType == WDG_INFO) {
+ result = new ModuleBase_WidgetLabel(theParent, myWidgetApi, myParentId);
- } else if (theType == WDG_INFO) {
- result = labelControl(theParent);
+ } else if (theType == WDG_DOUBLEVALUE) {
+ result = new ModuleBase_WidgetDoubleValue(theParent, myWidgetApi, myParentId);
} else if (theType == WDG_SHAPE_SELECTOR) {
- result = shapeSelectorControl(theParent);
+ result = new ModuleBase_WidgetShapeSelector(theParent, myWorkshop, myWidgetApi, myParentId);
} else if (theType == WDG_BOOLVALUE) {
- result = booleanControl(theParent);
+ result = new ModuleBase_WidgetBoolValue(theParent, myWidgetApi, myParentId);
} else if (theType == WDG_DOUBLEVALUE_EDITOR) {
- result = doubleValueEditor(theParent);
+ result = new ModuleBase_WidgetEditor(theParent, myWidgetApi, myParentId);
} else if (theType == WDG_FILE_SELECTOR) {
- result = fileSelectorControl(theParent);
+ result = new ModuleBase_WidgetFileSelector(theParent, myWidgetApi, myParentId);
} else if (theType == WDG_CHOICE) {
- result = choiceControl(theParent);
+ result = new ModuleBase_WidgetChoice(theParent, myWidgetApi,myParentId);
} else if (theType == WDG_STRINGVALUE) {
- result = lineEditControl(theParent);
+ result = new ModuleBase_WidgetLineEdit(theParent, myWidgetApi,myParentId);
} else if (theType == WDG_MULTISELECTOR) {
- result = multiSelectorControl(theParent);
+ result = new ModuleBase_WidgetMultiSelector(theParent, myWorkshop, myWidgetApi,myParentId);
- } else if (myWidgetApi->isContainerWidget() || myWidgetApi->isPagedWidget()) {
- result = createContainer(theType, theParent);
+ } else if (theType == WDG_TOOLBOX) {
+ result = new ModuleBase_WidgetToolbox(theParent, myWidgetApi, myParentId);
+
+ } else if (theType == WDG_SWITCH) {
+ result = new ModuleBase_WidgetSwitch(theParent, myWidgetApi, myParentId);
+ return result;
+
+ } else if (theType == WDG_TOOLBOX_BOX || theType == WDG_SWITCH_CASE) {
+ // Do nothing for "box" and "case"
+ result = NULL;
} else {
result = myWorkshop->module()->createWidgetByType(theType, theParent, myWidgetApi,
- myParentId, myModelWidgets);
+ myParentId);
#ifdef _DEBUG
if (!result) {qDebug("ModuleBase_WidgetFactory::fillWidget: find bad widget type");}
#endif
}
- return result;
-}
-
-QWidget* ModuleBase_WidgetFactory::createContainer(const std::string& theType, QWidget* theParent)
-{
- QWidget* aResult = NULL;
- if (theType == WDG_GROUP || theType == WDG_CHECK_GROUP) {
- QGroupBox* aGroupBox = new QGroupBox(theParent);
- aGroupBox->setCheckable(theType == WDG_CHECK_GROUP);
- aResult = aGroupBox;
- } else if (theType == WDG_TOOLBOX) {
- ModuleBase_WidgetToolbox* aWdg = new ModuleBase_WidgetToolbox(theParent, myWidgetApi, myParentId);
- myModelWidgets.append(aWdg);
- aResult = aWdg;
- } else if (theType == WDG_SWITCH) {
- aResult = new ModuleBase_WidgetSwitch(theParent);
- } else if (theType == WDG_TOOLBOX_BOX || theType == WDG_SWITCH_CASE) {
- // Do nothing for "box" and "case"
- aResult = NULL;
+ if (result) {
+ myModelWidgets.append(result);
}
-#ifdef _DEBUG
- else {qDebug() << "ModuleBase_WidgetFactory::fillWidget: find bad container type";}
-#endif
- return aResult;
-}
-
-QWidget* ModuleBase_WidgetFactory::labelControl(QWidget* theParent)
-{
- ModuleBase_WidgetLabel* aWgt =
- new ModuleBase_WidgetLabel(theParent, myWidgetApi, myParentId);
- myModelWidgets.append(aWgt);
- return aWgt;
-}
-
-QWidget* ModuleBase_WidgetFactory::doubleSpinBoxControl(QWidget* theParent)
-{
- ModuleBase_WidgetDoubleValue* aDblWgt =
- new ModuleBase_WidgetDoubleValue(theParent, myWidgetApi, myParentId);
- myModelWidgets.append(aDblWgt);
- return aDblWgt;
-}
-
-QWidget* ModuleBase_WidgetFactory::doubleValueEditor(QWidget* theParent)
-{
- ModuleBase_WidgetEditor* aWidget =
- new ModuleBase_WidgetEditor(theParent, myWidgetApi, myParentId);
- myModelWidgets.append(aWidget);
- return aWidget;
-}
-
-QWidget* ModuleBase_WidgetFactory::shapeSelectorControl(QWidget* theParent)
-{
- ModuleBase_WidgetShapeSelector* aSelector =
- new ModuleBase_WidgetShapeSelector(theParent, myWorkshop, myWidgetApi, myParentId);
- myModelWidgets.append(aSelector);
- return aSelector;
-}
-
-QWidget* ModuleBase_WidgetFactory::booleanControl(QWidget* theParent)
-{
- ModuleBase_WidgetBoolValue* aBoolWgt =
- new ModuleBase_WidgetBoolValue(theParent, myWidgetApi, myParentId);
- myModelWidgets.append(aBoolWgt);
- return aBoolWgt;
-}
-
-QWidget* ModuleBase_WidgetFactory::fileSelectorControl(QWidget* theParent)
-{
- ModuleBase_WidgetFileSelector* aFileSelectorWgt =
- new ModuleBase_WidgetFileSelector(theParent, myWidgetApi, myParentId);
- myModelWidgets.append(aFileSelectorWgt);
- return aFileSelectorWgt;
-}
-
-QWidget* ModuleBase_WidgetFactory::choiceControl(QWidget* theParent)
-{
- ModuleBase_WidgetChoice* aChoiceWgt =
- new ModuleBase_WidgetChoice(theParent, myWidgetApi,myParentId);
- myModelWidgets.append(aChoiceWgt);
- return aChoiceWgt;
-}
-
-QWidget* ModuleBase_WidgetFactory::lineEditControl(QWidget* theParent)
-{
- ModuleBase_WidgetLineEdit* aLineEditWgt =
- new ModuleBase_WidgetLineEdit(theParent, myWidgetApi,myParentId);
- myModelWidgets.append(aLineEditWgt);
- return aLineEditWgt;
-}
-
-QWidget* ModuleBase_WidgetFactory::multiSelectorControl(QWidget* theParent)
-{
- ModuleBase_WidgetMultiSelector* aMultiselectorWgt =
- new ModuleBase_WidgetMultiSelector(theParent, myWorkshop, myWidgetApi,myParentId);
- myModelWidgets.append(aMultiselectorWgt);
- return aMultiselectorWgt;
+ return result;
}
QString ModuleBase_WidgetFactory::qs(const std::string& theStdString)
* Author: sbh
*/
-#ifndef ModuleBase_WidgetFactory_H_
-#define ModuleBase_WidgetFactory_H_
+#ifndef MODULEBASE_WIDGETFACTORY_H_
+#define MODULEBASE_WIDGETFACTORY_H_
-#include "ModuleBase.h"
-#include "ModuleBase_ModelWidget.h"
+#include <ModuleBase.h>
+#include <ModuleBase_ModelWidget.h>
#include <QString>
#include <QList>
class QWidget;
class Config_WidgetAPI;
class ModuleBase_IWorkshop;
+class ModuleBase_PageBase;
/**
* \ingroup GUI
/// Creates content widget for property panel
/// \param theParent a parent widget
- void createWidget(QWidget* theParent);
+ void createWidget(ModuleBase_PageBase* theParent);
/// Returns list of model widgets
/// Create widget by its type
/// \param theType a type
/// \param theParent a parent widget
- QWidget* createWidgetByType(const std::string& theType, QWidget* theParent = NULL);
-
- /// Create a widget of container type
- /// \param theType a type
- /// \param theParent a parent widget
- QWidget* createContainer(const std::string& theType, QWidget* theParent);
-
- /// Create label widget
- /// \param theParent a parent widget
- QWidget* labelControl(QWidget* theParent);
-
- /// Create double spin box widget
- /// \param theParent a parent widget
- QWidget* doubleSpinBoxControl(QWidget* theParent);
-
- /// Create double value editor widget
- /// \param theParent a parent widget
- QWidget* doubleValueEditor(QWidget* theParent);
-
- /// Create shape selector widget
- /// \param theParent a parent widget
- QWidget* shapeSelectorControl(QWidget* theParent);
-
- /// Create boolean input widget
- /// \param theParent a parent widget
- QWidget* booleanControl(QWidget* theParent);
-
- /// Create file selector widget
- /// \param theParent a parent widget
- QWidget* fileSelectorControl(QWidget* theParent);
-
- /// Create choice widget (combo box)
- /// \param theParent a parent widget
- QWidget* choiceControl(QWidget* theParent);
-
- /// Create line edit widget
- /// \param theParent a parent widget
- QWidget* lineEditControl(QWidget* theParent);
-
- /// Create multi selector widget
- /// \param theParent a parent widget
- QWidget* multiSelectorControl(QWidget* theParent);
+ ModuleBase_ModelWidget* createWidgetByType(const std::string& theType,
+ QWidget* theParent = NULL);
/// Convert STD string to QT string
/// \param theStdString is STD string
*/
#include <ModuleBase_WidgetSwitch.h>
+#include <ModuleBase_ModelWidget.h>
+#include <ModuleBase_PageBase.h>
#include <QComboBox>
#include <QVBoxLayout>
#include <QSpacerItem>
-ModuleBase_WidgetSwitch::ModuleBase_WidgetSwitch(QWidget* parent)
- : QFrame(parent)
+
+ModuleBase_WidgetSwitch::ModuleBase_WidgetSwitch(QWidget* theParent, const Config_WidgetAPI* theData,
+ const std::string& theParentId)
+: ModuleBase_ModelWidget(theParent, theData, theParentId)
{
myMainLay = new QVBoxLayout(this);
myMainLay->setContentsMargins(2, 4, 2, 2);
myCombo = new QComboBox(this);
myCombo->hide();
myMainLay->addWidget(myCombo);
- this->setFrameShape(QFrame::StyledPanel);
+ //this->setFrameShape(QFrame::StyledPanel);
connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setCurrentIndex(int)));
connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SIGNAL(currentPageChanged(int)));
{
}
+QList<QWidget*> ModuleBase_WidgetSwitch::getControls() const
+{
+ QList<QWidget*> aList;
+ aList << myCombo;
+ return aList;
+}
+
int ModuleBase_WidgetSwitch::addPage(QWidget* theWidget, const QString& theName)
{
return insertPage(count(), theWidget, theName);
#define ModuleBase_WidgetSwitch_H_
#include <ModuleBase.h>
-#include <QFrame>
+#include <ModuleBase_ModelWidget.h>
class QComboBox;
class QVBoxLayout;
* \ingroup GUI
* Implements a model widget for swithch as a container widget. It can be defined in XML with "switch" keyword
*/
-class MODULEBASE_EXPORT ModuleBase_WidgetSwitch : public QFrame
+class MODULEBASE_EXPORT ModuleBase_WidgetSwitch : public ModuleBase_ModelWidget
{
-Q_OBJECT
+ Q_OBJECT
public:
/// Constructor
/// \param parent a parent widget
- ModuleBase_WidgetSwitch(QWidget* parent = NULL);
+ ModuleBase_WidgetSwitch(QWidget* theParent,
+ const Config_WidgetAPI* theData,
+ const std::string& theParentId);
virtual ~ModuleBase_WidgetSwitch();
+ virtual bool restoreValue() {
+ return false;
+ }
+
+ virtual QList<QWidget*> getControls() const;
+
+ virtual bool focusTo() {
+ return false;
+ }
+
/// Add a page to the widget
/// \param theWidget a page widget
/// \param theName a name of page
- int addPage(QWidget * theWidget, const QString & theName);
+ int addPage(QWidget* theWidget, const QString & theName);
/// Returns count of pages
int count() const;
void currentPageChanged(int);
protected:
+ virtual bool storeValueCustom() const {
+ return false;
+ }
/// Update widget
void refresh();
*/
#include <ModuleBase_WidgetToolbox.h>
+#include <ModuleBase_PageBase.h>
#include <ModuleBase_Tools.h>
#include <ModelAPI_AttributeString.h>
"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()));
{
}
-int ModuleBase_WidgetToolbox::addPage(QWidget* theWidget,
+int ModuleBase_WidgetToolbox::addPage(ModuleBase_PageBase* thePage,
const QString& theName, const QString& theCaseId)
{
myCaseIds << theCaseId;
- return myToolBox->addItem(theWidget, theName);
+ myPages << thePage;
+ QFrame* aFrame = dynamic_cast<QFrame*>(thePage);
+ aFrame->setFrameShape(QFrame::Box);
+ aFrame->setFrameStyle(QFrame::Sunken);
+ return myToolBox->addItem(aFrame, theName);
}
bool ModuleBase_WidgetToolbox::restoreValue()
bool isSignalsBlocked = myToolBox->blockSignals(true);
myToolBox->setCurrentIndex(idx);
myToolBox->blockSignals(isSignalsBlocked);
+ focusTo();
return true;
}
return aList;
}
+bool ModuleBase_WidgetToolbox::focusTo()
+{
+ int idx = myToolBox->currentIndex();
+ if (idx > myPages.count())
+ return false;
+ myPages[idx]->takeFocus();
+ repaint();
+ return true;
+}
+
+void ModuleBase_WidgetToolbox::activateCustom()
+{
+}
+
bool ModuleBase_WidgetToolbox::storeValueCustom() const
{
// A rare case when plugin was not loaded.
void ModuleBase_WidgetToolbox::onPageChanged()
{
storeValue();
+ focusTo();
}
#include <QToolBox>
+class ModuleBase_PageBase;
+
class ModuleBase_WidgetToolbox : public ModuleBase_ModelWidget
{
Q_OBJECT
virtual bool restoreValue();
virtual QList<QWidget*> getControls() const;
+ virtual bool focusTo();
- int addPage(QWidget* theWidget, const QString& theName, const QString& theCaseId);
+ int addPage(ModuleBase_PageBase* theWidget,
+ const QString& theName, const QString& theCaseId);
protected:
+ virtual void activateCustom();
virtual bool storeValueCustom() const;
protected slots:
private:
QToolBox* myToolBox;
QStringList myCaseIds;
+ QList<ModuleBase_PageBase*> myPages;
};
#endif /* MODULEBASE_WIDGETTOOLBOX_H_ */
}
}
-QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
- Config_WidgetAPI* theWidgetApi, std::string theParentId,
- QList<ModuleBase_ModelWidget*>& theModelWidgets)
+ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget* theParent,
+ Config_WidgetAPI* theWidgetApi, std::string theParentId)
{
XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(workshop());
XGUI_Workshop* aWorkshop = aConnector->workshop();
aConstraintShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch());
aWgt = aConstraintShapeSelectorWgt;
}
- if(aWgt)
- theModelWidgets.append(aWgt);
return aWgt;
}
virtual ~PartSet_Module();
/// Creates custom widgets for property panel
- virtual QWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
- Config_WidgetAPI* theWidgetApi, std::string theParentId,
- QList<ModuleBase_ModelWidget*>& theModelWidgets);
+ virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, QWidget* theParent,
+ Config_WidgetAPI* theWidgetApi, std::string theParentId);
/// Call back forlast tuning of property panel before operation performance
virtual void propertyPanelDefined(ModuleBase_Operation* theOperation);
PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule)
: QObject(theModule), myModule(theModule), myIsDragging(false), myDragDone(false),
myIsPropertyPanelValueChanged(false), myIsMouseOverWindow(false),
- myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true)
+ myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true),
+ myIsPopupMenuActive(false)
{
ModuleBase_IWorkshop* anIWorkshop = myModule->workshop();
ModuleBase_IViewer* aViewer = anIWorkshop->viewer();
{
get2dPoint(theWnd, theEvent, myClickedPoint);
+ myIsPopupMenuActive = theEvent->buttons() & Qt::RightButton;
+
if (!(theEvent->buttons() & Qt::LeftButton))
return;
void PartSet_SketcherMgr::onMouseReleased(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
{
+ if (myIsPopupMenuActive)
+ myIsPopupMenuActive = false;
+
ModuleBase_IWorkshop* aWorkshop = myModule->workshop();
ModuleBase_IViewer* aViewer = aWorkshop->viewer();
if (!aViewer->canDragByMouse())
return aCanDisplay;
}
}
+ if (myIsPopupMenuActive)
+ return aCanDisplay;
// during a nested create operation, the feature is redisplayed only if the mouse over view
// of there was a value modified in the property panel after the mouse left the view
std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
if (aSketchFeature.get() != NULL) {
- std::string anAttribute = SketchPlugin_Feature::CONSTRUCTION_ID();
+ std::string anAttribute = SketchPlugin_SketchEntity::CONSTRUCTION_ID();
std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(aSketchFeature->data()->attribute(anAttribute));
std::shared_ptr<SketchPlugin_Feature> aSketchFeature =
std::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
if (aSketchFeature.get() != NULL) {
- std::string anAttribute = SketchPlugin_Feature::CONSTRUCTION_ID();
+ std::string anAttribute = SketchPlugin_SketchEntity::CONSTRUCTION_ID();
std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeBoolean>(aSketchFeature->data()->attribute(anAttribute));
bool myIsPropertyPanelValueChanged; /// the state that value in the property panel is changed
bool myIsMouseOverWindow; /// the state that the mouse over the view
bool myIsMouseOverViewProcessed; /// the state whether the over view state is processed by mouseMove method
+ bool myIsPopupMenuActive; /// the state of the popup menu is shown
Point myCurrentPoint;
Point myClickedPoint;
DataPtr aData = aMyFeature->data();
AttributeSelectionPtr anAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
- (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID()));
+ (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
if (anAttr && aRes) {
DataPtr aData = aMyFeature->data();
AttributeSelectionPtr anAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
- (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID()));
+ (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
if (anAttr && aRes) {
#include "PartSet_WidgetSketchLabel.h"
#include "PartSet_Tools.h"
+#include "SketchPlugin_SketchEntity.h"
+
#include <XGUI_Workshop.h>
#include <XGUI_Displayer.h>
#include <XGUI_SelectionMgr.h>
DataPtr aData = feature()->data();
AttributeSelectionPtr aSelAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
- (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID()));
+ (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
if (aSelAttr) {
ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(aPrs.object());
if (aRes) {
<qresource>
<file>icons/arc.png</file>
<file>icons/circle.png</file>
+ <file>icons/color.png</file>
<file>icons/point.png</file>
<file>icons/plane.png</file>
<file>icons/axis.png</file>
SketchPlugin_Feature.h
SketchPlugin_Plugin.h
SketchPlugin_Sketch.h
+ SketchPlugin_SketchEntity.h
SketchPlugin_Line.h
SketchPlugin_Point.h
SketchPlugin_Circle.h
SketchPlugin_Feature.cpp
SketchPlugin_Plugin.cpp
SketchPlugin_Sketch.cpp
+ SketchPlugin_SketchEntity.cpp
SketchPlugin_Line.cpp
SketchPlugin_Point.cpp
SketchPlugin_Circle.cpp
const double tolerance = 1e-7;
SketchPlugin_Arc::SketchPlugin_Arc()
- : SketchPlugin_Feature()
+ : SketchPlugin_SketchEntity()
{
myStartUpdate = false;
myEndUpdate = false;
void SketchPlugin_Arc::initAttributes()
{
+ SketchPlugin_SketchEntity::initAttributes();
+
data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::type());
data()->addAttribute(START_ID(), GeomDataAPI_Point2D::type());
data()->addAttribute(END_ID(), GeomDataAPI_Point2D::type());
#define SketchPlugin_Arc_H_
#include "SketchPlugin.h"
-#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_SketchEntity.h>
#include <SketchPlugin_Sketch.h>
#include <GeomAPI_IPresentable.h>
* calculated when there is non-initialized attributes of the arc. The second is a result and
* it is calculated if all attributes are initialized.
*/
-class SketchPlugin_Arc : public SketchPlugin_Feature, public GeomAPI_IPresentable
+class SketchPlugin_Arc : public SketchPlugin_SketchEntity, public GeomAPI_IPresentable
{
/// to avoid cyclic dependencies in automatic updates: they mean that
/// update is performed right now and automatic updates are not needed
#include <GeomAlgoAPI_CompoundBuilder.h>
SketchPlugin_Circle::SketchPlugin_Circle()
- : SketchPlugin_Feature()
+ : SketchPlugin_SketchEntity()
{
}
void SketchPlugin_Circle::initAttributes()
{
+ SketchPlugin_SketchEntity::initAttributes();
+
data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::type());
data()->addAttribute(RADIUS_ID(), ModelAPI_AttributeDouble::type());
data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
#define SketchPlugin_Circle_H_
#include "SketchPlugin.h"
-#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_SketchEntity.h>
#include <SketchPlugin_Sketch.h>
#include <GeomAPI_IPresentable.h>
* \ingroup Plugins
* \brief Feature for creation of the new circle in PartSet.
*/
-class SketchPlugin_Circle : public SketchPlugin_Feature
+class SketchPlugin_Circle : public SketchPlugin_SketchEntity
{
public:
/// Circle feature kind
#include <ModelAPI_Document.h>
#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_AttributeBoolean.h>
-#include <GeomAPI_ICustomPrs.h>
#include <Config_PropManager.h>
-#define SKETCH_EDGE_COLOR "#ff0000"
-#define SKETCH_POINT_COLOR "#ff0000"
-#define SKETCH_EXTERNAL_EDGE_COLOR "#00ff00"
-#define SKETCH_CONSTRUCTION_COLOR "#000000"
-
class SketchPlugin_Sketch;
class GeomAPI_Pnt2d;
class Handle_AIS_InteractiveObject;
* \brief Feature for creation of the new feature in PartSet. This is an abstract class to give
* an interface to create the sketch feature preview.
*/
-class SketchPlugin_Feature : public ModelAPI_Feature, public GeomAPI_ICustomPrs
+class SketchPlugin_Feature : public ModelAPI_Feature
{
public:
- /// Reference to the construction type of the feature
- inline static const std::string& CONSTRUCTION_ID()
- {
- static const std::string MY_CONSTRUCTION_ID("Construction");
- return MY_CONSTRUCTION_ID;
- }
-
- /// Reference to the external edge or vertex as a AttributeSelection
- inline static const std::string& EXTERNAL_ID()
+ /// Returns true if this feature must be displayed in the history (top level of Part tree)
+ SKETCHPLUGIN_EXPORT virtual bool isInHistory()
{
- static const std::string MY_EXTERNAL_ID("External");
- return MY_EXTERNAL_ID;
+ return false;
}
- /// Returns true if this feature must be displayed in the history (top level of Part tree)
- SKETCHPLUGIN_EXPORT virtual bool isInHistory()
+ /// Returns true of the feature is created basing on the external shape of not-this-sketch object
+ SKETCHPLUGIN_EXPORT virtual bool isExternal() const
{
return false;
}
/// Returns true is sketch element is under the rigid constraint
SKETCHPLUGIN_EXPORT virtual bool isFixed() {return false;}
- /// Returns true of the feature is created basing on the external shape of not-this-sketch object
- inline bool isExternal() const
- {
- AttributeSelectionPtr aAttr = data()->selection(EXTERNAL_ID());
- if (aAttr)
- return aAttr->context().get() != NULL;
- return false;
- }
-
- /// Customize presentation of the feature
- virtual void customisePresentation(AISObjectPtr thePrs)
- {
- std::vector<int> aRGB;
-
- int aShapeType = thePrs->getShapeType();
- if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/)
- return;
-
- std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr =
- data()->boolean(SketchPlugin_Feature::CONSTRUCTION_ID());
- bool isConstruction = aConstructionAttr.get() != NULL && aConstructionAttr->value();
- if (aShapeType == 6) { // if this is an edge
- if (isConstruction) {
- thePrs->setWidth(1);
- thePrs->setLineStyle(3);
- aRGB = Config_PropManager::color("Visualization", "sketch_construction_color",
- SKETCH_CONSTRUCTION_COLOR);
- }
- else {
- thePrs->setWidth(3);
- thePrs->setLineStyle(0);
- if (isExternal()) {
- // Set color from preferences
- aRGB = Config_PropManager::color("Visualization", "sketch_external_color",
- SKETCH_EXTERNAL_EDGE_COLOR);
- }
- else {
- // Set color from preferences
- aRGB = Config_PropManager::color("Visualization", "sketch_edge_color",
- SKETCH_EDGE_COLOR);
- }
- }
- }
- else if (aShapeType == 7) { // otherwise this is a vertex
- // thePrs->setPointMarker(6, 2.);
- // Set color from preferences
- aRGB = Config_PropManager::color("Visualization", "sketch_point_color",
- SKETCH_POINT_COLOR);
- }
-
- if (!aRGB.empty())
- thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
- }
-
/// Returns the sketch of this feature
SketchPlugin_Sketch* sketch();
protected:
using namespace std;
SketchPlugin_Line::SketchPlugin_Line()
- : SketchPlugin_Feature()
+ : SketchPlugin_SketchEntity()
{}
void SketchPlugin_Line::initAttributes()
{
+ SketchPlugin_SketchEntity::initAttributes();
+
data()->addAttribute(START_ID(), GeomDataAPI_Point2D::type());
data()->addAttribute(END_ID(), GeomDataAPI_Point2D::type());
- data()->addAttribute(CONSTRUCTION_ID(), ModelAPI_AttributeBoolean::type());
data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
}
#define SketchPlugin_Line_H_
#include "SketchPlugin.h"
-#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_SketchEntity.h>
#include <SketchPlugin_Sketch.h>
#include <list>
* \ingroup Plugins
* \brief Feature for creation of the new part in PartSet.
*/
-class SketchPlugin_Line : public SketchPlugin_Feature
+class SketchPlugin_Line : public SketchPlugin_SketchEntity
{
public:
/// Arc feature kind
using namespace std;
SketchPlugin_Point::SketchPlugin_Point()
+ : SketchPlugin_SketchEntity()
{
}
void SketchPlugin_Point::initAttributes()
{
+ SketchPlugin_SketchEntity::initAttributes();
+
data()->addAttribute(SketchPlugin_Point::COORD_ID(), GeomDataAPI_Point2D::type());
data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
#include "SketchPlugin.h"
#include <SketchPlugin_Sketch.h>
-#include "SketchPlugin_Feature.h"
+#include "SketchPlugin_SketchEntity.h"
#include <list>
/**\class SketchPlugin_Point
* \ingroup Plugins
* \brief Feature for creation of a new point.
*/
-class SketchPlugin_Point : public SketchPlugin_Feature
+class SketchPlugin_Point : public SketchPlugin_SketchEntity
{
public:
/// Point feature kind
#include <SketchPlugin_Sketch.h>
#include <SketchPlugin_Feature.h>
+#include <SketchPlugin_SketchEntity.h>
#include <memory>
data()->addAttribute(SketchPlugin_Sketch::NORM_ID(), GeomDataAPI_Dir::type());
data()->addAttribute(SketchPlugin_Sketch::FEATURES_ID(), ModelAPI_AttributeRefList::type());
// the selected face, base for the sketcher plane, not obligatory
- data()->addAttribute(SketchPlugin_Feature::EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
+ data()->addAttribute(SketchPlugin_SketchEntity::EXTERNAL_ID(), ModelAPI_AttributeSelection::type());
ModelAPI_Session::get()->validators()->registerNotObligatory(
- getKind(), SketchPlugin_Feature::EXTERNAL_ID());
+ getKind(), SketchPlugin_SketchEntity::EXTERNAL_ID());
}
void SketchPlugin_Sketch::execute()
if (!aFeature->sketch()) // on load document the back references are missed
aFeature->setSketch(this);
// do not include the external edges into the result
- if (aFeature->data()->attribute(SketchPlugin_Feature::EXTERNAL_ID())) {
- if (aFeature->data()->selection(SketchPlugin_Feature::EXTERNAL_ID())->value())
+ if (aFeature->data()->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())) {
+ if (aFeature->data()->selection(SketchPlugin_SketchEntity::EXTERNAL_ID())->value())
continue;
}
// do not include the construction entities in the result
- if (aFeature->data()->attribute(SketchPlugin_Feature::CONSTRUCTION_ID())) {
- if (aFeature->data()->boolean(SketchPlugin_Feature::CONSTRUCTION_ID())->value())
+ if (aFeature->data()->attribute(SketchPlugin_SketchEntity::CONSTRUCTION_ID())) {
+ if (aFeature->data()->boolean(SketchPlugin_SketchEntity::CONSTRUCTION_ID())->value())
continue;
}
}
void SketchPlugin_Sketch::attributeChanged(const std::string& theID) {
- if (theID == SketchPlugin_Feature::EXTERNAL_ID()) {
+ if (theID == SketchPlugin_SketchEntity::EXTERNAL_ID()) {
std::shared_ptr<GeomAPI_Shape> aSelection =
- data()->selection(SketchPlugin_Feature::EXTERNAL_ID())->value();
+ data()->selection(SketchPlugin_SketchEntity::EXTERNAL_ID())->value();
if (aSelection) { // update arguments due to the selection value
// update the sketch plane
std::shared_ptr<GeomAPI_Pln> aPlane = GeomAlgoAPI_FaceBuilder::plane(aSelection);
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+#include "SketchPlugin_SketchEntity.h"
+
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+
+SketchPlugin_SketchEntity::SketchPlugin_SketchEntity()
+: SketchPlugin_Feature()
+{
+}
+
+void SketchPlugin_SketchEntity::initAttributes()
+{
+ data()->addAttribute(CONSTRUCTION_ID(), ModelAPI_AttributeBoolean::type());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CONSTRUCTION_ID());
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: SketchPlugin_SketchEntity.h
+// Created: 05 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef SketchPlugin_SketchEntity_H_
+#define SketchPlugin_SketchEntity_H_
+
+#include "SketchPlugin.h"
+#include "SketchPlugin_Feature.h"
+
+#include <ModelAPI_CompositeFeature.h>
+#include <GeomAPI_Shape.h>
+#include <GeomAPI_AISObject.h>
+#include <ModelAPI_Document.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeBoolean.h>
+#include <GeomAPI_ICustomPrs.h>
+
+#include <Config_PropManager.h>
+
+#define SKETCH_EDGE_COLOR "#ff0000"
+#define SKETCH_POINT_COLOR "#ff0000"
+#define SKETCH_EXTERNAL_EDGE_COLOR "#00ff00"
+#define SKETCH_CONSTRUCTION_COLOR "#000000"
+
+/**\class SketchPlugin_SketchEntity
+ * \ingroup Plugins
+ * \brief Sketch Entity for creation of the new feature in PartSet. This is an abstract class to give
+ * an interface to create the entity features such as line, circle, arc and point.
+ */
+class SketchPlugin_SketchEntity : public SketchPlugin_Feature, public GeomAPI_ICustomPrs
+{
+ public:
+ /// Reference to the construction type of the feature
+ inline static const std::string& CONSTRUCTION_ID()
+ {
+ static const std::string MY_CONSTRUCTION_ID("Construction");
+ return MY_CONSTRUCTION_ID;
+ }
+
+ /// Reference to the external edge or vertex as a AttributeSelection
+ inline static const std::string& EXTERNAL_ID()
+ {
+ static const std::string MY_EXTERNAL_ID("External");
+ return MY_EXTERNAL_ID;
+ }
+
+ /// Request for initialization of data model of the feature: adding all attributes
+ virtual void initAttributes();
+
+ /// Returns true of the feature is created basing on the external shape of not-this-sketch object
+ virtual bool isExternal() const
+ {
+ AttributeSelectionPtr aAttr = data()->selection(EXTERNAL_ID());
+ if (aAttr)
+ return aAttr->context().get() != NULL;
+ return false;
+ }
+
+ /// Customize presentation of the feature
+ virtual void customisePresentation(AISObjectPtr thePrs)
+ {
+ std::vector<int> aRGB;
+
+ int aShapeType = thePrs->getShapeType();
+ if (aShapeType != 6/*an edge*/ && aShapeType != 7/*a vertex*/)
+ return;
+
+ std::shared_ptr<ModelAPI_AttributeBoolean> aConstructionAttr =
+ data()->boolean(SketchPlugin_SketchEntity::CONSTRUCTION_ID());
+ bool isConstruction = aConstructionAttr.get() != NULL && aConstructionAttr->value();
+ if (aShapeType == 6) { // if this is an edge
+ if (isConstruction) {
+ thePrs->setWidth(1);
+ thePrs->setLineStyle(3);
+ aRGB = Config_PropManager::color("Visualization", "sketch_construction_color",
+ SKETCH_CONSTRUCTION_COLOR);
+ }
+ else {
+ thePrs->setWidth(3);
+ thePrs->setLineStyle(0);
+ if (isExternal()) {
+ // Set color from preferences
+ aRGB = Config_PropManager::color("Visualization", "sketch_external_color",
+ SKETCH_EXTERNAL_EDGE_COLOR);
+ }
+ else {
+ // Set color from preferences
+ aRGB = Config_PropManager::color("Visualization", "sketch_edge_color",
+ SKETCH_EDGE_COLOR);
+ }
+ }
+ }
+ else if (aShapeType == 7) { // otherwise this is a vertex
+ // thePrs->setPointMarker(6, 2.);
+ // Set color from preferences
+ aRGB = Config_PropManager::color("Visualization", "sketch_point_color",
+ SKETCH_POINT_COLOR);
+ }
+
+ if (!aRGB.empty())
+ thePrs->setColor(aRGB[0], aRGB[1], aRGB[2]);
+ }
+
+protected:
+ /// initializes mySketch
+ SketchPlugin_SketchEntity();
+};
+
+#endif
</feature>
<feature id="SketchPoint" title="Point" tooltip="Create a new point" icon=":icons/point.png">
<sketch-2dpoint_selector id="PointCoordindates" title="Point" tooltip="Point coordinates"/>
+ <boolvalue id="Construction" label="Construction" default="false" tooltip="Construction element" obligatory="0"/>
</feature>
<feature id="SketchLine" title="Line" tooltip="Create a new line" icon=":icons/line.png">
<sketch-2dpoint_selector id="StartPoint" title="Start point" tooltip="Start point coordinates" previous_feature_param="EndPoint"/>
<point2ddistance id="CircleRadius" first_point="CircleCenter" label="Radius:" min="0" step="1.0" default="0" icon=":icons/radius.png" tooltip="Set radius">
<validator id="GeomValidators_Positive"/>
</point2ddistance>
+ <boolvalue id="Construction" label="Construction" default="false" tooltip="Construction element" obligatory="0"/>
</feature>
<feature id="SketchArc" title="Arc" tooltip="Create a new arc" icon=":icons/arc.png">
<sketch-2dpoint_selector id="ArcCenter" title="Center" tooltip="Center of a circle"/>
<sketch-2dpoint_selector id="ArcStartPoint" title="Start point" tooltip="Start point"/>
<sketch-2dpoint_selector id="ArcEndPoint" title="End point" tooltip="End point"/>
+ <boolvalue id="Construction" label="Construction" default="false" tooltip="Construction element" obligatory="0"/>
</feature>
</group>
if (!aDesktop)
aDesktop = myWorkshop->salomeConnector()->desktop();
aDesktop->addAction(aAction);
+
addAction("DELETE_CMD", aAction);
aAction->setShortcut(Qt::Key_Delete);
aAction->setShortcutContext(Qt::ApplicationShortcut);
+ aAction = new QAction(QIcon(":pictures/color.png"), tr("Color"), this);
+ addAction("COLOR_CMD", aAction);
+
aAction = new QAction(QIcon(":pictures/eye_pencil.png"), tr("Show"), this);
addAction("SHOW_CMD", aAction);
if (hasFeature)
aMenu->addAction(action("DELETE_CMD"));
}
+ if (myWorkshop->canChangeColor())
+ aMenu->addAction(action("COLOR_CMD"));
+
aMenu->addSeparator();
aMenu->addActions(myWorkshop->objectBrowser()->actions());
aSubMenu->addActions(aMDI->actions());
}
}
+ if (myWorkshop->canChangeColor())
+ theMenu->addAction(action("COLOR_CMD"));
ModuleBase_IModule* aModule = myWorkshop->module();
if (aModule)
#include <ModelAPI_Data.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_Tools.h>
+#include <ModelAPI_AttributeIntArray.h>
#include <ModuleBase_ResultPrs.h>
aContext->Display(anAISIO, false);
aContext->SetDisplayMode(anAISIO, isShading? Shading : Wireframe, false);
- // Customization of presentation
- FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
- if (aFeature.get() != NULL) {
- GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
- if (aCustPrs.get() != NULL)
- aCustPrs->customisePresentation(theAIS);
- }
+
+ customizeObject(theObject);
if (aCanBeShaded) {
openLocalContext();
activateObjects(myActiveSelectionModes);
}
}
// Customization of presentation
- FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
- if (aFeature.get() != NULL) {
- GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
- if (aCustPrs.get() != NULL)
- aCustPrs->customisePresentation(aAISObj);
- }
+ customizeObject(theObject);
aContext->Redisplay(aAISIO, false);
if (isUpdateViewer)
}
}
}
+
+void XGUI_Displayer::customizeObject(ObjectPtr theObject)
+{
+ AISObjectPtr anAISObj = getAISObject(theObject);
+ // correct the result's color it it has the attribute
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+ if (aResult.get() != NULL && aResult->data()->attribute(ModelAPI_Result::COLOR_ID()).get() != NULL) {
+ AttributeIntArrayPtr aColorAttr = aResult->data()->intArray(ModelAPI_Result::COLOR_ID());
+ if (aColorAttr.get() && aColorAttr->size()) {
+ int aRed = aColorAttr->value(0);
+ int aGreen = aColorAttr->value(1);
+ int aBlue = aColorAttr->value(2);
+ anAISObj->setColor(aRed, aGreen, aBlue);
+ }
+ }
+ // Customization of presentation
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+ if (aFeature.get() != NULL) {
+ GeomCustomPrsPtr aCustPrs = std::dynamic_pointer_cast<GeomAPI_ICustomPrs>(aFeature);
+ if (aCustPrs.get() != NULL)
+ aCustPrs->customisePresentation(anAISObj);
+ }
+}
/// Opens local context. Does nothing if it is already opened.
void openLocalContext();
+ /** Update the object presentable properties such as color, lines width and other
+ * If the object is result with the color attribute value set, it is used,
+ * otherwise the customize is applyed to the object's feature if it is a custom prs
+ * \param theObject an object instance
+ */
+ void customizeObject(ObjectPtr theObject);
+
protected:
/// Reference to workshop
XGUI_Workshop* myWorkshop;
//#include <AppElements_Constants.h>
#include <ModuleBase_WidgetMultiSelector.h>
#include <ModuleBase_Tools.h>
+#include <ModuleBase_PageBase.h>
+#include <ModuleBase_PageWidget.h>
#include <QEvent>
#include <QFrame>
XGUI_PropertyPanel::XGUI_PropertyPanel(QWidget* theParent)
: ModuleBase_IPropertyPanel(theParent),
- myActiveWidget(NULL)
+ myActiveWidget(NULL),
+ myPanelPage(NULL)
{
this->setWindowTitle(tr("Property Panel"));
QAction* aViewAct = this->toggleViewAction();
setStyleSheet("::title { position: relative; padding-left: 5px; text-align: left center }");
QWidget* aContent = new QWidget(this);
- myMainLayout = new QGridLayout(aContent);
+ QGridLayout* aMainLayout = new QGridLayout(aContent);
const int kPanelColumn = 0;
int aPanelRow = 0;
- myMainLayout->setContentsMargins(3, 3, 3, 3);
+ aMainLayout->setContentsMargins(3, 3, 3, 3);
this->setWidget(aContent);
QFrame* aFrm = new QFrame(aContent);
aFrm->setFrameShape(QFrame::Panel);
QHBoxLayout* aBtnLay = new QHBoxLayout(aFrm);
ModuleBase_Tools::zeroMargins(aBtnLay);
- myMainLayout->addWidget(aFrm, aPanelRow++, kPanelColumn);
+ aMainLayout->addWidget(aFrm, aPanelRow++, kPanelColumn);
QStringList aBtnNames;
aBtnNames << QString(PROP_PANEL_HELP)
}
aBtnLay->insertStretch(1, 1);
- myCustomWidget = new QWidget(aContent);
- myCustomWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
- myMainLayout->addWidget(myCustomWidget, aPanelRow, kPanelColumn);
- setStretchEnabled(true);
+ myPanelPage = new ModuleBase_PageWidget(aContent);
+ myPanelPage->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
+ aMainLayout->addWidget(myPanelPage, aPanelRow, kPanelColumn);
}
XGUI_PropertyPanel::~XGUI_PropertyPanel()
if (myActiveWidget)
myActiveWidget->deactivate();
myWidgets.clear();
- qDeleteAll(myCustomWidget->children());
+ myPanelPage->clearPage();
myActiveWidget = NULL;
setWindowTitle(tr("Property Panel"));
}
return myWidgets;
}
-QWidget* XGUI_PropertyPanel::contentWidget()
+ModuleBase_PageBase* XGUI_PropertyPanel::contentWidget()
{
- return myCustomWidget;
+
+ return static_cast<ModuleBase_PageBase*>(myPanelPage);
}
void XGUI_PropertyPanel::updateContentWidget(FeaturePtr theFeature)
return;
if (theFeature->isAction() || !theFeature->data())
return;
- foreach(ModuleBase_ModelWidget* eachWidget, myWidgets)
- {
+ foreach(ModuleBase_ModelWidget* eachWidget, myWidgets) {
eachWidget->setFeature(theFeature);
eachWidget->restoreValue();
}
//}
}
-void XGUI_PropertyPanel::setStretchEnabled(bool isEnabled)
-{
- int aStretchIdx = myMainLayout->rowCount() - 1;
- if (aStretchIdx < 0)
- return;
- myMainLayout->setRowStretch(aStretchIdx, isEnabled ? 1 : 0);
-}
-
void XGUI_PropertyPanel::activateNextWidget()
{
activateNextWidget(myActiveWidget);
class XGUI_ActionsMgr;
class QKeyEvent;
class QGridLayout;
+class ModuleBase_PageBase;
+class ModuleBase_PageWidget;
/// Internal name of property panel widget
const static char* PROP_PANEL = "property_panel_dock";
/// Returns main widget of the property panel, which children will be created
/// by WidgetFactory using the XML definition
- QWidget* contentWidget();
+ ModuleBase_PageBase* contentWidget();
/// Brings back all widget created by widget factory for signal/slot
/// connections and further processing
/// Activate the next from current widget in the property panel
virtual void activateNextWidget();
- /// \brief Enable/Disable stretch area in the panel
- void setStretchEnabled(bool isEnabled);
-
/// Set Enable/Disable state of Cancel button
/// \param theEnabled Enable/Disable state of Cancel button
virtual void setCancelEnabled(bool theEnabled);
virtual void activateWidget(ModuleBase_ModelWidget* theWidget);
private:
- QWidget* myCustomWidget;
+ ModuleBase_PageWidget* myPanelPage;
QList<ModuleBase_ModelWidget*> myWidgets;
- QGridLayout* myMainLayout;
/// Currently active widget
ModuleBase_ModelWidget* myActiveWidget;
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_Validator.h>
+#include <ModelAPI_ResultGroup.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_AttributeIntArray.h>
//#include <PartSetPlugin_Part.h>
#include <ModuleBase_Tools.h>
#include <ModuleBase_IViewer.h>
#include<ModuleBase_FilterFactory.h>
+#include <ModuleBase_PageBase.h>
#include <Config_Common.h>
#include <Config_FeatureMessage.h>
#include <QMenu>
#include <QToolButton>
#include <QAction>
+#include <QDialog>
+#include <QDialogButtonBox>
+#include <QHBoxLayout>
+#include <QtxColorButton.h>
#ifdef _DEBUG
#include <QDebug>
myPropertyPanel->cleanContent();
aFactory.createWidget(myPropertyPanel->contentWidget());
- ModuleBase_Tools::zeroMargins(myPropertyPanel->contentWidget());
QList<ModuleBase_ModelWidget*> aWidgets = aFactory.getModelWidgets();
foreach (ModuleBase_ModelWidget* aWidget, aWidgets) {
activatePart(ResultPartPtr());
else if (theId == "DELETE_CMD")
deleteObjects(aObjects);
+ else if (theId == "COLOR_CMD")
+ changeColor(aObjects);
else if (theId == "SHOW_CMD")
showObjects(aObjects, true);
else if (theId == "HIDE_CMD")
return;
}
- SessionPtr aMgr = ModelAPI_Session::get();
QString aDescription = tr("Delete %1");
QStringList aObjectNames;
foreach (ObjectPtr aObj, theList) {
aObjectNames << QString::fromStdString(aObj->data()->name());
}
aDescription = aDescription.arg(aObjectNames.join(", "));
+ SessionPtr aMgr = ModelAPI_Session::get();
aMgr->startOperation(aDescription.toStdString());
std::set<FeaturePtr>::const_iterator anIt = aRefFeatures.begin(),
aLast = aRefFeatures.end();
updateCommandStatus();
}
+bool hasResults(QObjectPtrList theObjects, const std::set<std::string>& theTypes)
+{
+ bool isFoundResultType = false;
+ foreach(ObjectPtr anObj, theObjects)
+ {
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
+ if (aResult.get() == NULL)
+ continue;
+
+ isFoundResultType = theTypes.find(aResult->groupName()) != theTypes.end();
+ if (isFoundResultType)
+ break;
+ }
+ return isFoundResultType;
+}
+
+//**************************************************************
+bool XGUI_Workshop::canChangeColor() const
+{
+ QObjectPtrList aObjects = mySelector->selection()->selectedObjects();
+
+ std::set<std::string> aTypes;
+ aTypes.insert(ModelAPI_ResultGroup::group());
+ aTypes.insert(ModelAPI_ResultConstruction::group());
+ aTypes.insert(ModelAPI_ResultBody::group());
+ return hasResults(aObjects, aTypes);
+}
+
+//**************************************************************
+void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
+{
+ // 1. find the initial value of the color
+ AttributeIntArrayPtr aColorAttr;
+ foreach(ObjectPtr anObj, theObjects) {
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
+ if (aResult.get() != NULL) {
+ aColorAttr = aResult->data()->intArray(ModelAPI_Result::COLOR_ID());
+ }
+ }
+ // there is no object with the color attribute
+ if (aColorAttr.get() == NULL || aColorAttr->size() == 0)
+ return;
+ int aRed = aColorAttr->value(0);
+ int aGreen = aColorAttr->value(1);
+ int aBlue = aColorAttr->value(2);
+
+ // 2. show the dialog to change the value
+ QDialog* aDlg = new QDialog();
+ QVBoxLayout* aLay = new QVBoxLayout(aDlg);
+
+ QtxColorButton* aColorBtn = new QtxColorButton(aDlg);
+ aColorBtn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+
+ aLay->addWidget(aColorBtn);
+ aColorBtn->setColor(QColor(aRed, aGreen, aBlue));
+
+ QDialogButtonBox* aButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
+ Qt::Horizontal, aDlg);
+ connect(aButtons, SIGNAL(accepted()), aDlg, SLOT(accept()));
+ connect(aButtons, SIGNAL(rejected()), aDlg, SLOT(reject()));
+ aLay->addWidget(aButtons);
+
+ aDlg->move(QCursor::pos());
+ bool isDone = aDlg->exec() == QDialog::Accepted;
+ if (!isDone)
+ return;
+
+ QColor aColorResult = aColorBtn->color();
+ int aRedResult = aColorResult.red(),
+ aGreenResult = aColorResult.green(),
+ aBlueResult = aColorResult.blue();
+
+ if (aRedResult == aRed && aGreenResult == aGreen && aBlueResult == aBlue)
+ return;
+
+ // 3. abort the previous operation and start a new one
+ SessionPtr aMgr = ModelAPI_Session::get();
+ bool aWasOperation = aMgr->isOperation(); // keep this value
+ if (!aWasOperation) {
+ QString aDescription = contextMenuMgr()->action("DELETE_CMD")->text();
+ aMgr->startOperation(aDescription.toStdString());
+ }
+
+ // 4. set the value to all results
+ static Events_ID EVENT_DISP = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ foreach(ObjectPtr anObj, theObjects) {
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
+ if (aResult.get() != NULL) {
+ aColorAttr = aResult->data()->intArray(ModelAPI_Result::COLOR_ID());
+ if (aColorAttr.get() != NULL) {
+ if (!aColorAttr->size()) {
+ aColorAttr->setSize(3);
+ }
+ aColorAttr->setValue(0, aRedResult);
+ aColorAttr->setValue(1, aGreenResult);
+ aColorAttr->setValue(2, aBlueResult);
+ ModelAPI_EventCreator::get()->sendUpdated(anObj, EVENT_DISP);
+ }
+ }
+ }
+ if (!aWasOperation)
+ aMgr->finishOperation();
+ updateCommandStatus();
+}
+
//**************************************************************
void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible)
{
//! Delete features
void deleteObjects(const QObjectPtrList& theList);
+ //! Returns true if there is at least one selected body/construction/group result
+ //! \return boolean value
+ bool canChangeColor() const;
+
+ //! Change color of the features if it is possible
+ //! The operation is available for construction, body and group results
+ //! theObjects a list of selected objects
+ void changeColor(const QObjectPtrList& theObjects);
+
//! Show the given features in 3d Viewer
void showObjects(const QObjectPtrList& theList, bool isVisible);