From: nds Date: Mon, 6 Jul 2015 12:21:36 +0000 (+0300) Subject: Issue #705 Color of part change color of body X-Git-Tag: V_1.3.0~100 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c49ddc73a89962219d241fbb547fe3914dd9312c;p=modules%2Fshaper.git Issue #705 Color of part change color of body --- diff --git a/src/Model/Model_ResultPart.cpp b/src/Model/Model_ResultPart.cpp index a376cc88f..87552e362 100644 --- a/src/Model/Model_ResultPart.cpp +++ b/src/Model/Model_ResultPart.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -19,6 +20,13 @@ #include #include +void Model_ResultPart::initAttributes() +{ + // append the color attribute. It is empty, the attribute will be filled by a request + DataPtr aData = data(); + aData->addAttribute(COLOR_ID(), ModelAPI_AttributeIntArray::typeId()); +} + std::shared_ptr Model_ResultPart::partDoc() { return data()->document("PartDocument")->value(); diff --git a/src/Model/Model_ResultPart.h b/src/Model/Model_ResultPart.h index 11f813388..06c6efdad 100644 --- a/src/Model/Model_ResultPart.h +++ b/src/Model/Model_ResultPart.h @@ -22,6 +22,8 @@ class Model_ResultPart : public ModelAPI_ResultPart { TopoDS_Shape myShape; ///< shape of this part created from bodies (updated only of Part deactivation) public: + /// Request for initialization of data model of the result: adding all attributes + virtual void initAttributes(); /// Returns the part-document of this result MODEL_EXPORT virtual std::shared_ptr partDoc(); /// Part has no stored feature: this method returns NULL diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 25d0551e6..8bbf783e3 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1240,38 +1240,18 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects) // The objects are iterated until a first valid color is found std::vector aColor; foreach(ObjectPtr anObject, theObjects) { - if (anObject->groupName() == ModelAPI_ResultPart::group()) { - ResultPartPtr aPart = std::dynamic_pointer_cast(anObject); - DocumentPtr aPartDoc = aPart->partDoc(); - // the document should be checked on null, because in opened document if the part - // has not been activated yet, the part document is empty - if (!aPartDoc.get()) { - emit errorOccurred(QString::fromLatin1("Color can not be changed on a part with an empty document")); - } - else { - if (aPartDoc->size(ModelAPI_ResultBody::group()) > 0) { - ObjectPtr aObject = aPartDoc->object(ModelAPI_ResultBody::group(), 0); - ResultBodyPtr aBody = std::dynamic_pointer_cast(aObject); - if (aBody.get()) { - XGUI_CustomPrs::getResultColor(aBody, aColor); - } - } - } - } + ResultPtr aResult = std::dynamic_pointer_cast(anObject); + if (aResult.get()) + XGUI_CustomPrs::getResultColor(aResult, aColor); else { - ResultPtr aResult = std::dynamic_pointer_cast(anObject); - if (aResult.get()) - XGUI_CustomPrs::getResultColor(aResult, aColor); - else { - // TODO: remove the obtaining a color from the AIS object - // this does not happen never because: - // 1. The color can be changed only on results - // 2. The result can be not visualized in the viewer(e.g. Origin Construction) - AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject); - if (anAISObj.get()) { - aColor.resize(3); - anAISObj->getColor(aColor[0], aColor[1], aColor[2]); - } + // TODO: remove the obtaining a color from the AIS object + // this does not happen never because: + // 1. The color can be changed only on results + // 2. The result can be not visualized in the viewer(e.g. Origin Construction) + AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject); + if (anAISObj.get()) { + aColor.resize(3); + anAISObj->getColor(aColor[0], aColor[1], aColor[2]); } } if (!aColor.empty()) @@ -1302,24 +1282,8 @@ void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects) foreach(ObjectPtr anObj, theObjects) { ResultPtr aResult = std::dynamic_pointer_cast(anObj); if (aResult.get() != NULL) { - if (aResult->groupName() == ModelAPI_ResultPart::group()) { - ResultPartPtr aPart = std::dynamic_pointer_cast(aResult); - DocumentPtr aPartDoc = aPart->partDoc(); - // the document should be checked on null, because in opened document if the part - // has not been activated yet, the part document is empty - if (aPartDoc.get()) { - for (int i = 0; i < aPartDoc->size(ModelAPI_ResultBody::group()); i++) { - ObjectPtr aObject = aPartDoc->object(ModelAPI_ResultBody::group(), i); - ResultBodyPtr aBody = std::dynamic_pointer_cast(aObject); - std::vector aColorResult = aDlg->getColor(); - setColor(aBody, aColorResult); - } - } - } - else { - std::vector aColorResult = aDlg->getColor(); - setColor(aResult, aColorResult); - } + std::vector aColorResult = aDlg->getColor(); + setColor(aResult, aColorResult); } } if (!aWasOperation)