// 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, "false");
}
FeaturePtr ExchangePlugin_Plugin::createFeature(string theFeatureID)
Model_AttributeRefAttr.h
Model_AttributeRefList.h
Model_AttributeBoolean.h
+ Model_AttributeColor.h
Model_AttributeString.h
Model_AttributeInteger.h
Model_AttributeSelection.h
Model_AttributeRefAttr.cpp
Model_AttributeRefList.cpp
Model_AttributeBoolean.cpp
+ Model_AttributeColor.cpp
Model_AttributeString.cpp
Model_AttributeInteger.cpp
Model_AttributeSelection.cpp
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: Model_AttributeColor.cpp
+// Created: 6 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#include <Model_AttributeColor.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>
+
+void Model_AttributeColor::setValues(const int theRed,
+ const int theGreen,
+ const int theBlue)
+{
+ if (!myIsInitialized || myRed->Get() != theRed ||
+ myGreen->Get() != theGreen || myBlue->Get() != theBlue) {
+ myRed->Set(theRed);
+ myGreen->Set(theGreen);
+ myBlue->Set(theBlue);
+
+ owner()->data()->sendAttributeUpdated(this);
+ }
+}
+
+void Model_AttributeColor::setValuesRandom()
+{
+ setValues(300, 150, 40);
+}
+
+void Model_AttributeColor::values(int& theRed, int& theGreen, int& theBlue)
+{
+ theRed = myRed->Get();
+ theGreen = myGreen->Get();
+ theBlue = myBlue->Get();
+}
+
+Model_AttributeColor::Model_AttributeColor(TDF_Label& theLabel)
+{
+ // check the attribute could be already presented in this doc (after load document)
+ myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), myRed) == Standard_True;
+ if (!myIsInitialized) {
+ // create attribute: not initialized by value yet, just zero
+ myRed = TDataStd_Integer::Set(theLabel, 0);
+ myGreen = TDataStd_Integer::Set(theLabel, 0);
+ myBlue = TDataStd_Integer::Set(theLabel, 0);
+ }
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: Model_AttributeColor.h
+// Created: 6 Mar 2015
+// Author: Natalia ERMOLAEVA
+
+#ifndef MODEL_ATTRIBUTECOLOR_H_
+#define MODEL_ATTRIBUTECOLOR_H_
+
+#include <Model.h>
+#include <ModelAPI_AttributeColor.h>
+
+#include <TDF_Label.hxx>
+#include <TDataStd_Integer.hxx>
+
+#include <string>
+
+/**\class Model_AttributeColor
+ * \ingroup DataModel
+ * \brief Attribute that contains three integer values which define the color.
+ */
+
+class Model_AttributeColor : public ModelAPI_AttributeColor
+{
+ Handle_TDataStd_Integer myRed;
+ Handle_TDataStd_Integer myGreen;
+ Handle_TDataStd_Integer myBlue;
+ public:
+ /// Defines the color value
+ /// \param theRed the red part of the color
+ /// \param theRed the green part of the color
+ /// \param theRed the blue part of the color
+ MODELAPI_EXPORT virtual void setValues(const int theRed,
+ const int theGreen,
+ const int theBlue);
+
+ /// Fills the attribute values by a random color
+ MODELAPI_EXPORT virtual void setValuesRandom();
+
+ /// Returns the color value
+ MODELAPI_EXPORT virtual void values(int& theRed, int& theGreen, int& theBlue);
+
+ protected:
+ /// Initializes attibutes
+ Model_AttributeColor(TDF_Label& theLabel);
+
+ friend class Model_Data;
+};
+
+#endif
#include <Model_AttributeString.h>
#include <Model_AttributeSelection.h>
#include <Model_AttributeSelectionList.h>
+#include <Model_AttributeColor.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_AttributeColor::type()) {
+ anAttr = new Model_AttributeColor(anAttrLab);
}
// create also GeomData attributes here because only here the OCAF strucure is known
else if (theAttrType == GeomData_Point::type()) {
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)
aData->addAttribute(COLOR_ID(), ModelAPI_AttributeColor::type());
// set the default value
bool anIsRandomColor = Config_PropManager::boolean("Visualization", "random_result_color",
- false);
+ "false");
AttributeColorPtr aColorAttr = std::dynamic_pointer_cast<ModelAPI_AttributeColor>
- (aData->attribute(COLOR_ID()));
+ (aData->attribute(COLOR_ID()));
if (anIsRandomColor)
aColorAttr->setValuesRandom();
else {
/**\class ModelAPI_AttributeColor
* \ingroup DataModel
- * \brief API for the attribute that contains color (int, int, int).
+ * \brief API for the attribute that contains color (int, int, int). The color is in the range [0, 255]
* There is an opportunity to fill the attribute by a random color
*/
{
public:
/// Defines the color value
+ /// \param theRed the red part of the color
+ /// \param theRed the green part of the color
+ /// \param theRed the blue part of the color
MODELAPI_EXPORT virtual void setValues(const int theRed,
const int theGreen,
const int theBlue) = 0;
//**************************************************************
#include <QDialog>
#include <QHBoxLayout>
-#include <QLineEdit>
+#include <QtxColorButton.h>
+#include <ModelAPI_AttributeColor.h>
void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
{
- // 1. find the initial value of the material
- std::string aFirstValue = "";
- foreach(ObjectPtr anObj, theObjects)
- {
+ // 1. find the initial value of the color
+ AttributeColorPtr aColorAttr;
+ foreach(ObjectPtr anObj, theObjects) {
ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
- if (aResult.get() == NULL)
- continue;
+ if (aResult.get() != NULL) {
+ AttributePtr anAttr = aResult->data()->attribute(ModelAPI_Result::COLOR_ID());
+ if (anAttr.get() != NULL)
+ aColorAttr = std::dynamic_pointer_cast<ModelAPI_AttributeColor>(anAttr);
+ }
}
+ // there is no object with the color attribute
+ if (aColorAttr.get() == NULL)
+ return;
+ int aRed, aGreen, aBlue;
+ aColorAttr->values(aRed, aGreen, aBlue);
// 2. show the dialog to change the value
QDialog aDlg;
QHBoxLayout* aLay = new QHBoxLayout(&aDlg);
- QLineEdit* anEditor = new QLineEdit("QString::number(theValue)", &aDlg);
- anEditor->setText(aFirstValue.c_str());
- anEditor->selectAll();
- aLay->addWidget(anEditor);
+ QtxColorButton* aColorBtn = new QtxColorButton(&aDlg);
+ aLay->addWidget(aColorBtn);
+ aColorBtn->setColor(QColor(aRed, aGreen, aBlue));
QPoint aPoint = QCursor::pos();
aDlg.move(aPoint);
if (!isDone)
return;
- std::string aValue = anEditor->text().toStdString();
+ 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
+ if(!isActiveOperationAborted())
+ return;
// 4. set the value to all results
+ foreach(ObjectPtr anObj, theObjects) {
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
+ if (aResult.get() != NULL) {
+ AttributePtr anAttr = aResult->data()->attribute(ModelAPI_Result::COLOR_ID());
+ if (anAttr.get() != NULL) {
+ aColorAttr = std::dynamic_pointer_cast<ModelAPI_AttributeColor>(anAttr);
+ if (aColorAttr.get() != NULL)
+ aColorAttr->setValues(aRedResult, aGreenResult, aBlueResult);
+ }
+ }
+ }
}
//**************************************************************