- Added: Added ability to assign colors on subshape of shape. This work for Part and for PartSet
- Modified Python dump: can dump colored objects to python script:
For object inside part: Cylinder_1.result().setColor(model.selection("FACE", "Cylinder_1_1/Face_2"), 85, 170, 0)
For PartSet: Part_1.result().setColor(model.selection("FACE", "Part_1/Sphere_1_1/Face_1"), 249, 225, 104)
- In Preferences -> Shaper -> Visualization: Added checkbox for enable/disable this functionality - Set color on subshape of result
} else if (aFormatName == "STL") {
exportSTL(theFileName);
return;
+ }else if (aFormatName == "STEP") {
+ exportSTEP(theFileName);
+ return;
}
// make shape for export from selected shapes
bool aResult = false;
if (aFormatName == "BREP") {
aResult = BREPExport(theFileName, aFormatName, aShape, anError);
- } else if (aFormatName == "STEP") {
- aResult = STEPExport(theFileName, aShapes, aContexts, anError);
} else if (aFormatName.substr(0, 4) == "IGES") {
aResult = IGESExport(theFileName, aFormatName, aShape, anError);
+ } else if (aFormatName == "STEP")
+ {
+ //aResult = STEPExport(theFileName, aFormatName, aShape, anError);
} else {
anError = "Unsupported format: " + aFormatName;
}
// LCOV_EXCL_STOP
}
+void ExchangePlugin_ExportFeature::exportSTEP(const std::string & theFileName)
+{
+ AttributeSelectionListPtr aSelectionList =
+ selectionList(ExchangePlugin_ExportFeature::SELECTION_LIST_ID());
+
+ std::list<GeomShapePtr> aShapeList;
+ std::string anError;
+ std::map<GeomShapePtr, std::vector<int>> aColoredShapes;
+ for (int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex)
+ {
+ AttributeSelectionPtr anAttrSelection = aSelectionList->value(anIndex);
+ std::shared_ptr<GeomAPI_Shape> aCurShape = anAttrSelection->value();
+ if (!aCurShape.get())
+ aCurShape = anAttrSelection->context()->shape();
+ if (!aCurShape.get())
+ continue;
+ #ifndef HAVE_SALOME
+ ResultPtr aRes = anAttrSelection->context();
+ std::vector<int> aColor;
+ ModelAPI_Tools::getColor(aRes, aColor);
+ ModelAPI_Tools::getColoredShapes(aRes, aColoredShapes);
+ if (aColor.size() == 3)
+ {
+ aColoredShapes[aCurShape] = aColor;
+ }
+ #endif
+ aShapeList.push_back(aCurShape);
+ }
+ std::shared_ptr<GeomAPI_Shape> aShape =
+ aShapeList.size() == 1 ? aShapeList.front() : GeomAlgoAPI_CompoundBuilder::compound(aShapeList);
+ #ifndef HAVE_SALOME
+ bool aRes = true;// STEPExport(theFileName, aShape, aColoredShapes, anError);
+ #else
+ bool aRes = true;// STEPExport(theFileName, "STEP", aShape, anError);
+ #endif
+
+ if (!anError.empty() || !aRes)
+ {
+ setError("An error occurred while exporting " + theFileName + ": " + anError);
+ return;
+ }
+ }
+
bool ExchangePlugin_ExportFeature::isMacro() const
{
if (!data().get() || !data()->isValid())
/// Performs export to STL file
EXCHANGEPLUGIN_EXPORT void exportSTL(const std::string& theFileName);
+
+ /// Performs export to STEP file
+ EXCHANGEPLUGIN_EXPORT void exportSTEP(const std::string & theFileName);
};
#endif /* EXPORT_EXPORTFEATURE_H_ */
#include <Quantity_NameOfColor.hxx>
#include <BRepBndLib.hxx>
+#include <AIS_ColoredShape.hxx>
#include <AIS_InteractiveObject.hxx>
#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
return true;
}
+bool GeomAPI_AISObject::setColor(const std::shared_ptr<GeomAPI_Shape>& theSubShape,
+ int theR, int theG, int theB)
+{
+ Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+ if (anAIS.IsNull())
+ return false;
+ Quantity_Color aColor(theR / 255., theG / 255., theB / 255., Quantity_TOC_RGB);
+
+ Handle(AIS_ColoredShape) aShape = Handle(AIS_ColoredShape)::DownCast(anAIS);
+ aShape->SetCustomColor(theSubShape->impl<TopoDS_Shape>(), aColor);
+ return true;
+}
+
void GeomAPI_AISObject::getColor(int& theR, int& theG, int& theB)
{
Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
GEOMAPI_EXPORT
bool setColor(int theR, int theG, int theB);
+ /** \brief Assigns the color for the subshape
+ * \param[in] theSubShape subshape that belongs to shape
+ * \param[in] theR value of the red component
+ * \param[in] theG value of the green component
+ * \param[in] theB value of the blue component
+ */
+ GEOMAPI_EXPORT
+ bool setColor(const std::shared_ptr<GeomAPI_Shape>& theSubShape,
+ int theR, int theG, int theB);
+
/** \brief Returns the color for the shape
* \param[in] theR value of the red component
* \param[in] theG value of the green component
#include <STEPCAFControl_Writer.hxx>
#include <Interface_Static.hxx>
#include <Quantity_Color.hxx>
+#include <XSControl_WorkSession.hxx>
+#include <TopExp_Explorer.hxx>
#include <Basics_OCCTVersion.hxx>
}
return theError.empty();
}
+
+bool STEPExport(const std::string& theFileName,
+ const std::shared_ptr<GeomAPI_Shape>& theShape,
+ std::map<std::shared_ptr<GeomAPI_Shape>, std::vector<int>>& theColoredShapes,
+ std::string& theError)
+{
+ Handle(TDocStd_Document) aDoc = new TDocStd_Document("MDTV-CAF");
+#ifdef _DEBUG
+ std::cout << "Export STEP into file " << theFileName << std::endl;
+#endif
+ GeomAlgoAPI_Tools::Localizer loc;
+
+ Handle(XSControl_WorkSession) aWS = new XSControl_WorkSession();
+ STEPCAFControl_Writer aWriter(aWS, false);
+ aWriter.SetColorMode(true);
+ aWriter.SetNameMode(true);
+
+ IFSelect_ReturnStatus aStatus;
+ //VRV: OCC 4.0 migration
+ Interface_Static::SetCVal("xstep.cascade.unit", "M");
+ Interface_Static::SetCVal("write.step.unit", "M");
+ Interface_Static::SetIVal("write.step.nonmanifold", 1);
+
+ TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+ Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
+ Handle(XCAFDoc_ColorTool) aColorTool = XCAFDoc_DocumentTool::ColorTool(aDoc->Main());
+
+ TDF_Label aShapeLabel = aShapeTool->AddShape(aShape, false);
+ TDF_Label aRefShapeLab;
+ if (aShapeTool->GetReferredShape(aShapeLabel, aRefShapeLab))
+ aShapeLabel = aRefShapeLab;
+
+ if (theColoredShapes.find(theShape) != theColoredShapes.end())
+ {
+ std::vector<int> aColor = theColoredShapes.find(theShape)->second;
+ Quantity_Color aQColor(aColor[0] / 255.,
+ aColor[1] / 255.,
+ aColor[2] / 255.,
+ Quantity_TOC_RGB);
+ aColorTool->SetColor(aShapeLabel, aQColor, XCAFDoc_ColorGen);
+ theColoredShapes.erase(theShape);
+ }
+
+ for (std::map<GeomShapePtr, std::vector<int>>::iterator anIter(theColoredShapes.begin());
+ anIter != theColoredShapes.end(); ++anIter)
+ {
+ TopoDS_Shape aSubShape = (anIter->first)->impl<TopoDS_Shape>();
+ if (aSubShape.IsNull())
+ continue;
+ bool sub = theShape->isSubShape(anIter->first);
+ Quantity_Color aColor(anIter->second.at(0) / 255.,
+ anIter->second.at(1) / 255.,
+ anIter->second.at(2) / 255.,
+ Quantity_TOC_RGB);
+ TDF_Label aSubShapeLabel;
+ aShapeTool->Search(aShape, aSubShapeLabel);
+ if (!aSubShapeLabel.IsNull())
+ {
+ aColorTool->SetColor(aSubShapeLabel, aColor, XCAFDoc_ColorSurf);
+ }
+ }
+ /*for (TopExp_Explorer aFaceExp(aShape, TopAbs_FACE); aFaceExp.More(); aFaceExp.Next())
+ {
+ TDF_Label aSubShapeLabel;
+ std::shared_ptr<GeomAPI_Shape> aFace(new GeomAPI_Shape);
+ aFace->setImpl(new TopoDS_Shape(aFaceExp.Value()));
+ if (theColoredShapes.find(theShape) == theColoredShapes.end())
+ continue;
+ aShapeTool->Search(aFaceExp.Value(), aSubShapeLabel);
+ if (!aSubShapeLabel.IsNull())
+ {
+ std::vector<int> aColor = theColoredShapes.find(theShape)->second;
+ Quantity_Color aQColor(aColor[0] / 255.,
+ aColor[1] / 255.,
+ aColor[2] / 255.,
+ Quantity_TOC_RGB);
+ aColorTool->SetColor(aSubShapeLabel, aQColor, XCAFDoc_ColorSurf);
+ }
+ }*/
+ /*for (std::map<GeomShapePtr, std::vector<int>>::const_iterator anIter(theColoredShapes.cbegin());
+ anIter != theColoredShapes.cend(); ++anIter)
+ {
+ TopoDS_Shape aSubShape = (anIter->first)->impl<TopoDS_Shape>();
+ if (aSubShape.IsNull())
+ continue;
+ bool sub = theShape->isSubShape(anIter->first);
+ Quantity_Color aColor(anIter->second.at(0) / 255.,
+ anIter->second.at(1) / 255.,
+ anIter->second.at(2) / 255.,
+ Quantity_TOC_RGB);
+ //TDF_Label aColorLabel = aColorTool->AddColor(aColor);
+ TDF_Label aSubShapeLabel = aShape.IsEqual(aSubShape) ?
+ aShapeLabel : aShapeTool->AddSubShape(aShapeLabel, aSubShape);
+ aColorTool->SetColor(aSubShapeLabel, aColor,
+ aShape.IsEqual(aSubShape) ? XCAFDoc_ColorGen : XCAFDoc_ColorSurf);
+ }*/
+
+ /////////////////
+ TDF_LabelSequence aLabels;
+ aColorTool->GetColors(aLabels);
+ Standard_Integer i, nbc = aLabels.Length();
+ for (i = 1; i <= nbc; ++i)
+ {
+ Quantity_Color aColorQ;
+ TDF_Label aLabel = aLabels.Value(i);
+ aColorTool->GetColor(aLabel, aColorQ);
+ int a = 0;
+ }
+ TDF_LabelSequence aShapesL;
+ aShapeTool->GetFreeShapes(aShapesL);
+ nbc = aShapesL.Length();
+ for (i = 1; i <= nbc; ++i)
+ {
+ Quantity_Color aColorR;
+ TDF_LabelSequence aSubShapesL;
+ TopoDS_Shape aShape2;
+ aShapeTool->GetShape(aShapesL.Value(i), aShape2);
+ TDF_Label aShapeLabel = aShapeTool->FindShape(aShape2);
+ aColorTool->GetColor(aShapeLabel, XCAFDoc_ColorGen, aColorR);
+ aShapeTool->GetSubShapes(aShapesL.Value(i), aSubShapesL);
+ for (TDF_LabelSequence::Iterator aLabIt(aSubShapesL); aLabIt.More(); aLabIt.Next())
+ {
+ const TDF_Label& aSubShapeLab = aLabIt.Value();
+ TopoDS_Shape aSubShape = aShapeTool->GetShape(aSubShapeLab);
+ aColorTool->GetColor(aSubShapeLab, XCAFDoc_ColorSurf, aColorR);
+ }
+ }
+ /////////////////////
+ bool aaaaaa = aWriter.GetColorMode();
+ if (!aWriter.Transfer(aDoc, STEPControl_AsIs))
+ {
+ theError = "Error: Failed transfer to file.";
+ return false;
+ }
+ aStatus = aWriter.Write(theFileName.c_str());
+ if (aStatus != IFSelect_RetDone)
+ {
+
+ theError = "Error: Failed write to file.";
+ return false;
+ }
+ return true;
+}
#include <GeomAlgoAPI.h>
#include <string>
+#include <map>
+#include <vector>
#include <list>
#include <memory>
const std::list<std::shared_ptr<ModelAPI_Result> >& theResults,
std::string& theError);
+GEOMALGOAPI_EXPORT
+bool STEPExport(const std::string& theFileName,
+ const std::shared_ptr<GeomAPI_Shape>& theShape,
+ std::map<std::shared_ptr<GeomAPI_Shape>, std::vector<int>>& theColoredShapes,
+ std::string& theError);
+
#endif /* GEOMALGOAPI_STEPEXPORT_H_ */
Handle_XCAFDoc_ShapeTool shapeTool = XCAFDoc_DocumentTool::ShapeTool(mainLabel);
Handle_XCAFDoc_ColorTool colorTool = XCAFDoc_DocumentTool::ColorTool(mainLabel);
Handle(XCAFDoc_MaterialTool) materialTool = XCAFDoc_DocumentTool::MaterialTool(mainLabel);
+ TDF_LabelSequence aLabels, aLabelSS;
+ colorTool->GetColors(aLabels);
+ Standard_Integer i, nbc = aLabels.Length();
+ for (i = 1; i <= nbc; ++i)
+ {
+ Quantity_Color aColorQ;
+ TDF_Label aLabel = aLabels.Value(i);
+ colorTool->GetColor(aLabel, aColorQ);
+ int a = 0;
+ }
+ shapeTool->GetShapes(aLabels);
+ Quantity_Color aColorR;
+ for (TDF_LabelSequence::Iterator aLabIt(aLabels); aLabIt.More(); aLabIt.Next())
+ {
+ const TDF_Label& aShapeLabel = aLabIt.Value();
+ TopoDS_Shape aSubShape = shapeTool->GetShape(aShapeLabel);
+ shapeTool->GetSubShapes(aShapeLabel, aLabelSS);
+ colorTool->GetColor(aShapeLabel, XCAFDoc_ColorGen, aColorR);
+ for (TDF_LabelSequence::Iterator aLabIt2(aLabelSS); aLabIt2.More(); aLabIt2.Next())
+ {
+ const TDF_Label& aSubShapeLab = aLabIt.Value();
+ TopoDS_Shape aSubShape = shapeTool->GetShape(aSubShapeLab);
+ colorTool->GetColor(aSubShapeLab, XCAFDoc_ColorSurf, aColorR);
+ }
+
+ }
+
// traverse the labels recursively to set attributes on shapes
setShapeAttributes(shapeTool, colorTool, materialTool, mainLabel,
TopLoc_Location(),theResultBody,theMaterialShape,false);
return L""; // not defined
}
+std::wstring Model_Data::name(std::shared_ptr<GeomAPI_Shape> theSubShape)
+{
+ std::wstring aShapeName = L"";
+ std::wstring aResultName = name();
+ if (aResultName == L"")
+ return aShapeName;
+
+ AttributeSelectionPtr aSelectionAttribute;
+ ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(myObject);
+ if (aResBody.get())
+ aSelectionAttribute = aResBody->selection();
+ else
+ {
+ ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(myObject);
+ aSelectionAttribute = aPart->selection();
+ }
+ aSelectionAttribute->setValue(myObject, theSubShape);
+ aShapeName = aSelectionAttribute->namingName();
+ aSelectionAttribute->reset();
+
+ return aShapeName;
+}
+
void Model_Data::setName(const std::wstring& theName)
{
bool isModified = false;
#include <map>
#include <list>
#include <string>
+#include <vector>
#include <set>
class ModelAPI_Attribute;
Model_Data();
/// Returns the name of the feature visible by the user in the object browser
MODEL_EXPORT virtual std::wstring name();
+ /// Returns the name of the shape
+ MODEL_EXPORT virtual std::wstring name(std::shared_ptr<GeomAPI_Shape> theSubShape);
/// Defines the name of the feature visible by the user in the object browser
MODEL_EXPORT virtual void setName(const std::wstring& theName);
/// Return \c true if the object has been renamed by the user
#include <TDF_Delta.hxx>
#include <TDF_AttributeDelta.hxx>
#include <TDF_AttributeDeltaList.hxx>
+#include <TDF_AttributeIterator.hxx>
#include <TDF_ListIteratorOfAttributeDeltaList.hxx>
#include <TDF_ListIteratorOfLabelList.hxx>
#include <TDF_LabelMap.hxx>
return myObjs->index(theObject, theAllowFolder);
}
+const int Model_Document::index(std::shared_ptr<ModelAPI_Result> theResult,
+ std::shared_ptr<GeomAPI_Shape> theShape,
+ const bool theAllowFolder)
+{
+ return myObjs->index(theResult, theShape, theAllowFolder);
+}
+
int Model_Document::size(const std::string& theGroupID, const bool theAllowFolder)
{
if (myObjs == 0) // may be on close
return mySelectionFeature->selectionList("selection");
}
+/// Feature that is used for use selection attribute
+class Model_SelectionInResult : public ModelAPI_Feature
+{
+public:
+ /// Nothing to do in constructor
+ Model_SelectionInResult() : ModelAPI_Feature() {}
+
+ /// Returns the unique kind of a feature
+ virtual const std::string& getKind()
+ {
+ static std::string MY_KIND("InternalSelectionInResult");
+ return MY_KIND;
+ }
+ /// Request for initialization of data model of the object: adding all attributes
+ virtual void initAttributes()
+ {
+ data()->addAttribute("selection", ModelAPI_AttributeSelection::typeId());
+ }
+ /// Nothing to do in the execution function
+ virtual void execute() {}
+};
+
+AttributeSelectionPtr Model_Document::selectionInResult()
+{
+ FeaturePtr aFeatureNameGen = FeaturePtr(new Model_SelectionInResult);
+
+ TDF_Label aFeatureLab = generalLabel().FindChild(TAG_SELECTION_FEATURE);
+ std::shared_ptr<Model_Data> aData(new Model_Data);
+ aData->setLabel(aFeatureLab.FindChild(1));
+ aData->setObject(aFeatureNameGen);
+ aFeatureNameGen->setDoc(myObjs->owner());
+ aFeatureNameGen->setData(aData);
+ std::wstring aName = id() + L"_Part";
+ aFeatureNameGen->data()->setName(aName);
+ aFeatureNameGen->setDoc(myObjs->owner());
+ aFeatureNameGen->initAttributes();
+ aFeatureNameGen->init();
+
+ return aFeatureNameGen->selection("selection");
+}
+
FeaturePtr Model_Document::lastFeature()
{
if (myObjs)
}
}
+void Model_Document::storeShape(const std::shared_ptr<ModelAPI_Data> theData,
+ const std::shared_ptr<ModelAPI_Result> theResult,
+ const std::shared_ptr<GeomAPI_Shape> theShape)
+{
+ if (index(theData->owner()) == -1)
+ return;
+ int anIndex = index(theResult, theShape);
+ if (anIndex == -1)
+ myObjs->storeShape(theData, theResult, theShape);
+}
+
void Model_Document::restoreNodesState(std::list<bool>& theStates) const
{
TDF_Label aLab = generalLabel().FindChild(TAG_NODES_STATE);
class Handle_Model_Document;
class Model_Objects;
class ModelAPI_AttributeSelectionList;
+class TopoDS_Shape;
/**\class Model_Document
* \ingroup DataModel
//! \returns index started from zero, or -1 if object is invisible or belongs to another document
MODEL_EXPORT virtual const int index(std::shared_ptr<ModelAPI_Object> theObject,
const bool theAllowFolder = false);
+ //! Returns the shape index in the result.
+ //! \param theResult result
+ //! \param theShape result subshape
+ //! \returns index started from zero, or -1 if shape is not stored or is not a subshape of the result
+ MODEL_EXPORT virtual const int index(std::shared_ptr<ModelAPI_Result> theResult,
+ std::shared_ptr<GeomAPI_Shape> theShape,
+ const bool theAllowFolder = false);
//! Internal sub-document by ID
MODEL_EXPORT virtual std::shared_ptr<Model_Document> subDoc(int theDocID);
//! for calculation of selection externally from the document
std::shared_ptr<ModelAPI_AttributeSelectionList> selectionInPartFeature();
+ //! Returns the selection attribute that is used
+ std::shared_ptr<ModelAPI_AttributeSelection> selectionInResult();
+
/// Stores in the document boolean flags: states of the nodes in the object browser.
/// Normally is called outside of the transaction, just before "save".
virtual void storeNodesState(const std::list<bool>& theStates);
+ /// Store Shape from Result to document
+ virtual void storeShape(const std::shared_ptr<ModelAPI_Data> theData,
+ const std::shared_ptr<ModelAPI_Result> theResult,
+ const std::shared_ptr<GeomAPI_Shape> theShape);
+
/// Returns the stored nodes states. Normally it is called just after "open".
/// Appends the values to theStates list.
virtual void restoreNodesState(std::list<bool>& theStates) const;
friend class Model_ResultPart;
friend class Model_ResultBody;
friend class Model_ResultConstruction;
+ friend class Model_SelectionInResult;
friend class Model_SelectionNaming;
friend class Model_BodyBuilder;
friend class DFBrowser;
#include <TDataStd_Integer.hxx>
#include <TDataStd_Comment.hxx>
#include <TDF_ChildIDIterator.hxx>
+#include <TDataStd_IntegerArray.hxx>
#include <TDataStd_ReferenceArray.hxx>
#include <TDataStd_HLabelArray1.hxx>
#include <TDF_Reference.hxx>
#include <TDF_ChildIDIterator.hxx>
#include <TDF_LabelMapHasher.hxx>
#include <TDF_LabelMap.hxx>
+#include <TDF_CopyLabel.hxx>
#include <TDF_ListIteratorOfLabelList.hxx>
+// relocate to other file
+#include <TNaming_Builder.hxx>
+#include <TNaming_NamedShape.hxx>
+
+
// for TDF_Label map usage
static Standard_Integer HashCode(const TDF_Label& theLab, const Standard_Integer theUpper);
static Standard_Boolean IsEqual(const TDF_Label& theLab1, const TDF_Label& theLab2);
// feature sub-labels
static const int TAG_FEATURE_ARGUMENTS = 1; ///< where the arguments are located
static const int TAG_FEATURE_RESULTS = 2; ///< where the results are located
+static const int TAG_RESULT_SHAPES = 2; ///< where the shapes are located
///
/// 0:1:2 - where features are located
/// 0:1:2:N:1 - data of the feature N
/// 0:1:2:N:2:K:1 - data of the K result of the feature N
+/// 0:1:2:N:2:K:2:M:1 - data of the M shape of the K result of the feature N
Model_Objects::Model_Objects(TDF_Label theMainLab) : myMain(theMainLab)
{
return -1;
}
+const int Model_Objects::index(std::shared_ptr<ModelAPI_Result> theResult,
+ std::shared_ptr<GeomAPI_Shape> theShape,
+ const bool theAllowFolder)
+{
+ ResultBodyPtr aMain = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+ aMain = ModelAPI_Tools::mainBody(aMain);
+
+ int anIndex = -1;
+ if (aMain.get())
+ anIndex = index(aMain, theAllowFolder);
+ else
+ anIndex = index(theResult, theAllowFolder);
+
+ if (anIndex == -1)
+ return -1; // Object not store to document
+ TDF_Label aShapesLabel = shapesFromResult(resultLabel(theResult->data(), anIndex));
+
+ int aShapesIndex = 0;
+ for (TDF_ChildIterator anIt(aShapesLabel); anIt.More(); anIt.Next(), ++aShapesIndex)
+ {
+ Handle(TNaming_NamedShape) aCurShape;
+ if (anIt.Value().FindAttribute(TNaming_NamedShape::GetID(), aCurShape))
+ {
+ if (aCurShape->Get().IsSame(theShape->impl<TopoDS_Shape>()))
+ {
+ return aShapesIndex;
+ }
+ }
+ }
+ //not found
+ return -1;
+}
+
int Model_Objects::size(const std::string& theGroupID, const bool theAllowFolder)
{
createHistory(theGroupID);
return myMain.FindChild(TAG_OBJECTS);
}
+TDF_Label Model_Objects::shapesFromResult(TDF_Label theResult) const
+{
+ return theResult.Father().FindChild(TAG_RESULT_SHAPES);
+}
+
+void Model_Objects::setAttribute(const Handle(TDF_Attribute)& theAttribute,
+ std::shared_ptr<ModelAPI_Result> theResult,
+ std::shared_ptr<GeomAPI_Shape> theShape)
+{
+ ResultBodyPtr aMain = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+ aMain = ModelAPI_Tools::mainBody(aMain);
+ TDF_Label aResultLabel;
+ if (aMain.get())
+ aResultLabel = resultLabel(theResult->data(), index(aMain));
+ else
+ aResultLabel = resultLabel(theResult->data(), index(theResult));
+ TDF_Label anAttributeLabel = subShapeLabel(aResultLabel, index(theResult, theShape)).FindChild(TAG_FEATURE_ARGUMENTS);
+
+ if (Standard_GUID::IsEqual(theAttribute->ID(), TDataStd_IntegerArray::GetID()))
+ {
+ Handle(TDataStd_IntegerArray) anColor;
+ Handle(TDataStd_IntegerArray) anAttr =
+ Handle(TDataStd_IntegerArray)::DownCast(theAttribute);
+
+ if (anAttributeLabel.FindAttribute(TDataStd_IntegerArray::GetID(), anColor))
+ {
+ anAttributeLabel.ForgetAttribute(TDataStd_IntegerArray::GetID());
+ }
+ anAttributeLabel.AddAttribute(anAttr);
+ static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+ ModelAPI_EventCreator::get()->sendUpdated(theResult, anEvent);
+ }
+}
+
+Handle(TDF_Attribute) Model_Objects::getAttribute(const Standard_GUID& theID,
+ std::shared_ptr<ModelAPI_Result> theResult,
+ std::shared_ptr<GeomAPI_Shape> theShape)
+{
+ ResultBodyPtr aMain = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+ aMain = ModelAPI_Tools::mainBody(aMain);
+
+ int anIndex = index(theResult, theShape);
+ Handle(TDataStd_IntegerArray) anColor;
+
+ if (anIndex != -1)
+ {
+ TDF_Label aResultLabel;
+ if (aMain.get())
+ aResultLabel = resultLabel(theResult->data(), index(aMain));
+ else
+ aResultLabel = resultLabel(theResult->data(), index(theResult));
+
+ TDF_Label anAttributeLabel = subShapeLabel(aResultLabel, anIndex).FindChild(TAG_FEATURE_ARGUMENTS);
+ anAttributeLabel.FindAttribute(TDataStd_IntegerArray::GetID(), anColor);
+ }
+ return anColor;
+}
+
+void Model_Objects::getColoredShapes(const std::shared_ptr<ModelAPI_Result> theResult,
+ std::map<std::shared_ptr<GeomAPI_Shape>, std::vector<int>>& theColoredShapes)
+{
+ ResultBodyPtr aMainBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+ aMainBody = ModelAPI_Tools::mainBody(aMainBody);
+ TDF_Label aShapesLabel;
+ if (aMainBody.get())
+ aShapesLabel = shapesFromResult(resultLabel(theResult->data(), index(aMainBody)));
+ else
+ aShapesLabel = shapesFromResult(resultLabel(theResult->data(), index(theResult)));
+
+ for (TDF_ChildIterator aChilds(aShapesLabel); aChilds.More(); aChilds.Next())
+ {
+ TDF_Label aCurSubShape = aChilds.Value();
+ Handle(TNaming_NamedShape) aNamedShape;
+ aCurSubShape.FindAttribute(TNaming_NamedShape::GetID(), aNamedShape);
+ if (aNamedShape.IsNull())
+ continue;
+
+ std::shared_ptr<GeomAPI_Shape> aSub(new GeomAPI_Shape);
+ aSub->setImpl(new TopoDS_Shape(aNamedShape->Get()));
+
+ Handle(TDataStd_IntegerArray) aColorAttr;
+ std::vector<int> aColor;
+ aCurSubShape.FindChild(TAG_FEATURE_ARGUMENTS).FindAttribute(TDataStd_IntegerArray::GetID(), aColorAttr);
+ if (aColorAttr.IsNull())
+ continue;
+ for (int anIndex = aColorAttr->Lower(); anIndex <= aColorAttr->Upper(); ++anIndex)
+ aColor.push_back(aColorAttr->Value(anIndex));
+ if (aColor.size() != 3)
+ continue;
+
+ theColoredShapes[aSub] = aColor;
+ }
+}
+
+void Model_Objects::removeShapeColors(const std::shared_ptr<ModelAPI_Result> theResult)
+{
+ ResultBodyPtr aMainBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+ aMainBody = ModelAPI_Tools::mainBody(aMainBody);
+
+ TDF_Label aShapesLabel;
+ if (aMainBody.get())
+ aShapesLabel = shapesFromResult(resultLabel(theResult->data(), index(aMainBody)));
+ else
+ {
+ ResultPartPtr aResPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theResult);
+ if (!aResPart.get())
+ return;
+ aShapesLabel = shapesFromResult(resultLabel(theResult->data(), index(aResPart)));
+ }
+ for (TDF_ChildIterator aChilds(aShapesLabel); aChilds.More(); aChilds.Next())
+ {
+ TDF_Label aCurSubShape = aChilds.Value();
+ Handle(TNaming_NamedShape) aNamedShape;
+ aCurSubShape.FindAttribute(TNaming_NamedShape::GetID(), aNamedShape);
+ if (aNamedShape.IsNull())
+ continue;
+
+ aCurSubShape.FindChild(TAG_FEATURE_ARGUMENTS).ForgetAttribute(TDataStd_IntegerArray::GetID());
+ }
+}
+
static std::wstring composeName(const std::string& theFeatureKind, const int theIndex)
{
std::stringstream aNameStream;
return aData->label().Father().FindChild(TAG_FEATURE_RESULTS).FindChild(theResultIndex + 1);
}
+TDF_Label Model_Objects::subShapeLabel(TDF_Label& theResultLabel,
+ const int theResultIndex)
+{
+ return theResultLabel.Father().FindChild(TAG_RESULT_SHAPES).FindChild(theResultIndex + 1);
+}
+
bool Model_Objects::hasCustomName(DataPtr theFeatureData,
ResultPtr theResult,
int /*theResultIndex*/,
}
}
+void Model_Objects::storeShape(std::shared_ptr<ModelAPI_Data> theData,
+ std::shared_ptr<ModelAPI_Result> theResult,
+ std::shared_ptr<GeomAPI_Shape> theShape,
+ const int theResultIndex)
+{
+ std::shared_ptr<Model_Data> aResultData =
+ std::dynamic_pointer_cast<Model_Data>(theResult->data());
+ TDF_Label aResultLabel = resultLabel(aResultData, index(theData->owner()));
+ TDF_Label aShapesLabel = shapesFromResult(aResultLabel);
+
+ int anIndex = aShapesLabel.NbChildren();
+ TDF_Label aSubShapeLabel = subShapeLabel(aResultLabel, anIndex);
+
+ Handle(TNaming_NamedShape) aNS;
+ if (aSubShapeLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS))
+ return;
+
+ // GeomAPI_Shape -> TNaming_NamedShape
+ TNaming_Builder aBuilder(aSubShapeLabel);
+ aBuilder.Select(theShape->impl<TopoDS_Shape>(), theShape->impl<TopoDS_Shape>());
+}
+
std::shared_ptr<ModelAPI_ResultConstruction> Model_Objects::createConstruction(
const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex)
{
bool Model_Objects::isLater(FeaturePtr theLater, FeaturePtr theCurrent) const
{
- if (theLater->getKind() == "InternalSelectionInPartFeature")
+ if (theLater->getKind() == "InternalSelectionInPartFeature" || theLater->getKind() == "InternalSelectionInResult")
return true;
std::shared_ptr<Model_Data> aLaterD = std::static_pointer_cast<Model_Data>(theLater->data());
std::shared_ptr<Model_Data> aCurrentD = std::static_pointer_cast<Model_Data>(theCurrent->data());
const int index(std::shared_ptr<ModelAPI_Object> theObject,
const bool theAllowFolder = false);
+ //! Returns the shape index in the result.
+ //! \param theResult result
+ //! \param theShape result subshape
+ //! \returns index started from zero, or -1 if shape is not stored or is not a subshape of the result
+ const int index(std::shared_ptr<ModelAPI_Result> theResult,
+ std::shared_ptr<GeomAPI_Shape> theShape,
+ const bool theAllowFolder = false);
+
//! Returns the feature in the group by the index (started from zero)
//! \param theGroupID group that contains a feature
//! \param theIndex zero-based index of feature in the group
bool removeFromFolder(const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures,
const bool theBefore = true);
+ //! set attribute to subShape
+ void setAttribute(const Handle(TDF_Attribute)& theAttribute,
+ std::shared_ptr<ModelAPI_Result> theResult,
+ std::shared_ptr<GeomAPI_Shape> theShape);
+
+ //! get attribute from subshape
+ Handle(TDF_Attribute) getAttribute(const Standard_GUID& theID,
+ std::shared_ptr<ModelAPI_Result> theResult,
+ std::shared_ptr<GeomAPI_Shape> theShape);
+
+ //! Get colored shapes from result
+ void getColoredShapes(const std::shared_ptr<ModelAPI_Result> theResult,
+ std::map<std::shared_ptr<GeomAPI_Shape>, std::vector<int>>& theColoredShapes);
+
+ //! Forget subshape colors
+ void removeShapeColors(const std::shared_ptr<ModelAPI_Result> theResult);
+
//! Sets the owner of this manager
void setOwner(DocumentPtr theDoc);
//! Returns (creates if needed) the features label
TDF_Label featuresLabel() const;
+ //! Returns (creates if needed) the shapes label from result label
+ TDF_Label shapesFromResult(TDF_Label theResult) const;
+
//! Initializes feature with a unique name in this group (unique name is generated as
//! feature type + "_" + index
void setUniqueName(FeaturePtr theFeature);
const int theResultIndex = 0,
const std::wstring& theNameShape = L"");
+ //! Allows to store the shape from result in the data tree of the document
+ void storeShape(std::shared_ptr<ModelAPI_Data> theData,
+ std::shared_ptr<ModelAPI_Result> theResult,
+ std::shared_ptr<GeomAPI_Shape> theShape,
+ const int theResultIndex = 0);
+
//! returns the label of result by index; creates this label if it was not created before
TDF_Label resultLabel(const std::shared_ptr<ModelAPI_Data>& theFeatureData,
const int theResultIndex);
+ //! Returns the label of result subshapes by index; creates this label if it was not created before
+ TDF_Label subShapeLabel(TDF_Label& theResultLabel,
+ const int theResultIndex);
+
//! Updates the results list of the feature basing on the current data tree
//! theProcessed is used to avoid update twice (since the function is recursive)
void updateResults(FeaturePtr theFeature, std::set<FeaturePtr>& theProcessed);
#include <ModelAPI_Object.h>
#include <ModelAPI_Events.h>
#include <ModelAPI_Tools.h>
+#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_AttributeImage.h>
#include <Model_Data.h>
#include <Events_Loop.h>
#include <TopExp_Explorer.hxx>
#include <TopTools_MapOfShape.hxx>
#include <TDataStd_UAttribute.hxx>
+#include <TDataStd_IntegerArray.hxx>
+#include <TNaming_Tool.hxx>
+#include <TDF_Reference.hxx>
// if this attribute exists, the shape is connected topology
Standard_GUID kIsConnectedTopology("e51392e0-3a4d-405d-8e36-bbfe19858ef5");
myColorsShape[ theName ] = color;
}
+void Model_ResultBody::setSubShapeColor(const std::shared_ptr<ModelAPI_Result> theResult,
+ const std::shared_ptr<GeomAPI_Shape> theShape,
+ const std::vector<int>& theColor)
+{
+ TopoDS_Shape aShape = this->shape()->impl<TopoDS_Shape>();
+ TopoDS_Shape aSubShape = theShape->impl<TopoDS_Shape>();
+ if (!this->shape()->isSubShape(theShape))
+ return;
+
+ Model_Objects* anObjects = std::dynamic_pointer_cast<Model_Document>(document())->objects();
+ document()->storeShape(data(), theResult, theShape);
+
+ Handle(TDataStd_IntegerArray) aColor = new TDataStd_IntegerArray();
+ aColor->Init(0, 2);
+ aColor->SetValue(0, theColor[0]);
+ aColor->SetValue(1, theColor[1]);
+ aColor->SetValue(2, theColor[2]);
+ anObjects->setAttribute(aColor, theResult, theShape);
+}
+
+void Model_ResultBody::getSubShapeColor(const std::shared_ptr<ModelAPI_Result> theResult, const std::shared_ptr<GeomAPI_Shape> theShape, std::vector<int>& theColor)
+{
+ TopoDS_Shape aShape = this->shape()->impl<TopoDS_Shape>();
+ TopoDS_Shape aSubShape = theShape->impl<TopoDS_Shape>();
+ if (!this->shape()->isSubShape(theShape))
+ return;
+
+ Model_Objects* anObjects = std::dynamic_pointer_cast<Model_Document>(document())->objects();
+ Handle(TDataStd_IntegerArray) anAttr = Handle(TDataStd_IntegerArray)::DownCast(
+ anObjects->getAttribute(TDataStd_IntegerArray::GetID(), theResult, theShape));
+ if (anAttr.IsNull())
+ return;
+ for (int anIndex = anAttr->Lower(); anIndex <= anAttr->Upper(); ++anIndex)
+ theColor.push_back(anAttr->Value(anIndex));
+ if (theColor.size() != 3)
+ theColor.clear();
+}
+
+void Model_ResultBody::getColoredShapes(const std::shared_ptr<ModelAPI_Result> theResult,
+ std::map<GeomShapePtr, std::vector<int>>& theColoredShapes)
+{
+ Model_Objects* anObjects = std::dynamic_pointer_cast<Model_Document>(document())->objects();
+ anObjects->getColoredShapes(theResult, theColoredShapes);
+}
+
+void Model_ResultBody::removeShapeColors(const std::shared_ptr<ModelAPI_Result> theResult)
+{
+ Model_Objects* anObjects = std::dynamic_pointer_cast<Model_Document>(document())->objects();
+ anObjects->removeShapeColors(theResult);
+}
+
+std::shared_ptr<ModelAPI_AttributeSelection> Model_ResultBody::selection()
+{
+ AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<Model_Document>
+ (document())->selectionInResult();
+ return aSelAttr;
+}
+
std::wstring Model_ResultBody::addShapeName(std::shared_ptr<GeomAPI_Shape> theshape,
const std::wstring& theName ){
/// Add color for shape Name read shape in step file
void addShapeColor( const std::wstring& theName,std::vector<int>& color) override;
+ /// Add color to sub shape
+ void setSubShapeColor(const std::shared_ptr<ModelAPI_Result> theResult,
+ const std::shared_ptr<GeomAPI_Shape> theShape,
+ const std::vector<int>& theColor);
+
+ /// Get color from sub shape
+ void getSubShapeColor(const std::shared_ptr<ModelAPI_Result> theResult,
+ const std::shared_ptr<GeomAPI_Shape> theShape,
+ std::vector<int>& theColor);
+
+ /// Get colored shapes from result
+ void getColoredShapes(const std::shared_ptr<ModelAPI_Result> theResult,
+ std::map<std::shared_ptr<GeomAPI_Shape>, std::vector<int>>& theColoredShapes);
+
+ /// Forget subshape colors
+ void removeShapeColors(const std::shared_ptr<ModelAPI_Result> theResult);
+
/// Set the map of name and color read shape in step file
void setShapeName(std::map< std::wstring,
std::shared_ptr<GeomAPI_Shape>>& theShapeName,
std::map< std::wstring,
std::vector<int>>& theColorsShape) override;
+ /// Return Attribute selection
+ MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_AttributeSelection> selection();
+
/// Find the name of shape read in step file
std::wstring findShapeName(std::shared_ptr<GeomAPI_Shape> theShape) override;
#include <ModelAPI_Data.h>
#include <Model_Data.h>
+#include <Model_Objects.h>
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Feature.h>
#include <TNaming_Tool.hxx>
#include <TNaming_NamedShape.hxx>
#include <TDataStd_Name.hxx>
+#include <TDataStd_IntegerArray.hxx>
#include <TopoDS_Compound.hxx>
#include <BRep_Builder.hxx>
#include <TopExp_Explorer.hxx>
return false; // something is wrong
}
+std::shared_ptr<ModelAPI_AttributeSelection> Model_ResultPart::selection()
+{
+ AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<Model_Document>
+ (document())->selectionInResult();
+ return aSelAttr;
+}
+
gp_Trsf Model_ResultPart::sumTrsf() {
gp_Trsf aResult;
if (myTrsf) {
return aResult;
}
+void Model_ResultPart::setSubShapeColor(const std::shared_ptr<GeomAPI_Shape>& theShape,
+ const std::vector<int>& theColor)
+{
+ TopoDS_Shape aShape = this->shape()->impl<TopoDS_Shape>();
+ TopoDS_Shape aSubShape = theShape->impl<TopoDS_Shape>();
+ if (!this->shape()->isSubShape(theShape))
+ return;
+
+ Model_Objects* anObjects = std::dynamic_pointer_cast<Model_Document>(document())->objects();
+
+ document()->storeShape(data(), original(), theShape);
+ Handle(TDataStd_IntegerArray) aColor = new TDataStd_IntegerArray();
+ aColor->Init(0, 2);
+ aColor->SetValue(0, theColor[0]);
+ aColor->SetValue(1, theColor[1]);
+ aColor->SetValue(2, theColor[2]);
+ anObjects->setAttribute(aColor, original(), theShape);
+}
+
+void Model_ResultPart::getSubShapeColor(const std::shared_ptr<GeomAPI_Shape>& theShape,
+ std::vector<int>& theColor)
+{
+ TopoDS_Shape aShape = this->shape()->impl<TopoDS_Shape>();
+ TopoDS_Shape aSubShape = theShape->impl<TopoDS_Shape>();
+ if (!this->shape()->isSubShape(theShape))
+ return;
+
+ Model_Objects* anObjects = std::dynamic_pointer_cast<Model_Document>(document())->objects();
+ Handle(TDataStd_IntegerArray) anAttr = Handle(TDataStd_IntegerArray)::DownCast(
+ anObjects->getAttribute(TDataStd_IntegerArray::GetID(), original(), theShape));
+ if (anAttr.IsNull())
+ return;
+ for (int anIndex = anAttr->Lower(); anIndex <= anAttr->Upper(); ++anIndex)
+ theColor.push_back(anAttr->Value(anIndex));
+ if (theColor.size() != 3)
+ theColor.clear();
+}
+
+void Model_ResultPart::getColoredShapes(std::map<std::shared_ptr<GeomAPI_Shape>,
+ std::vector<int>>&theColoredShapes)
+{
+ Model_Objects* anObjects = std::dynamic_pointer_cast<Model_Document>(document())->objects();
+ anObjects->getColoredShapes(original(), theColoredShapes);
+}
+
+void Model_ResultPart::removeShapeColors()
+{
+ Model_Objects* anObjects = std::dynamic_pointer_cast<Model_Document>(document())->objects();
+ anObjects->removeShapeColors(original());
+}
+
std::shared_ptr<GeomAPI_Shape> Model_ResultPart::selectionValue(const int theIndex)
{
std::shared_ptr<GeomAPI_Shape> aResult;
#include <ModelAPI_ResultPart.h>
#include <TopoDS_Shape.hxx>
#include <gp_Trsf.hxx>
+#include <map>
/**\class Model_ResultPart
* \ingroup DataModel
MODEL_EXPORT virtual bool updateInPart(const int theIndex);
/// Returns the shape by the name in the part
MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> shapeInPart(
- const std::wstring& theName, const std::string& theType, int& theIndex);
+ const std::wstring& theName, const std::string& theType, int& theIndex); /// Set color on subshape
+ MODEL_EXPORT virtual void setSubShapeColor(const std::shared_ptr<GeomAPI_Shape>& theShape,
+ const std::vector<int>& theColor);
+
+ /// Get color on subshape
+ MODEL_EXPORT virtual void getSubShapeColor(const std::shared_ptr<GeomAPI_Shape>& theShape,
+ std::vector<int>& theColor);
+
+ /// Get colored shapes from result
+ MODEL_EXPORT virtual void getColoredShapes(std::map<std::shared_ptr<GeomAPI_Shape>,
+ std::vector<int>>&theColoredShapes);
+
+ /// Forget subshape colors
+ MODEL_EXPORT virtual void removeShapeColors();
+
/// Updates the selection inside of the part as a geometrical selection
MODEL_EXPORT virtual bool combineGeometrical(const int theIndex, std::wstring& theNewName);
/// Updates the shape-result of the part (called on Part feature execution)
/// Loading the part from file
MODEL_EXPORT virtual void loadPart();
+ /// Return Attribute selection
+ MODEL_EXPORT virtual std::shared_ptr<ModelAPI_AttributeSelection> selection();
+
protected:
/// makes a result on a temporary feature (an action)
Model_ResultPart();
#include "ModelAPI.h"
#include <string>
+#include <vector>
#include <list>
#include <set>
#include <memory>
/// Returns the name of the feature visible by the user in the object browser
virtual std::wstring name() = 0;
+ /// Returns the name of the shape
+ virtual std::wstring name(std::shared_ptr<GeomAPI_Shape> theSubShape) = 0;
/// Defines the name of the feature visible by the user in the object browser
virtual void setName(const std::wstring& theName) = 0;
/// Return \c true if the object has been renamed by the user
#include <vector>
#include <list>
#include <set>
+#include <map>
class ModelAPI_Feature;
class ModelAPI_Folder;
//! \returns index started from zero, or -1 if object is invisible or belongs to another document
virtual const int index(std::shared_ptr<ModelAPI_Object> theObject,
const bool theAllowFolder = false) = 0;
+ //! Returns the shape index in the result.
+ //! \param theResult result
+ //! \param theShape result subshape
+ //! \returns index started from zero, or -1 if shape is not stored or is not a subshape of the result
+ virtual const int index(std::shared_ptr<ModelAPI_Result> theResult,
+ std::shared_ptr<GeomAPI_Shape> theShape,
+ const bool theAllowFolder = false) = 0;
//! Returns the number of objects in the group of objects
//! \param theGroupID group of objects
/// Appends the values to theStates list.
MODELAPI_EXPORT virtual void restoreNodesState(std::list<bool>& theStates) const = 0;
+ /// Store Shape from Result to document
+ MODELAPI_EXPORT virtual void storeShape(const std::shared_ptr<ModelAPI_Data> theData,
+ const std::shared_ptr<ModelAPI_Result> theResult,
+ const std::shared_ptr<GeomAPI_Shape> theShape) = 0;
+
/// Just removes all features without touching the document data (to be able undo)
MODELAPI_EXPORT virtual void eraseAllFeatures() = 0;
MODELAPI_EXPORT virtual void addShapeColor
(const std::wstring& theName, std::vector<int>& theColor) = 0;
+ /// Add color to sub shape
+ MODELAPI_EXPORT virtual void setSubShapeColor(const std::shared_ptr<ModelAPI_Result> theResult,
+ const std::shared_ptr<GeomAPI_Shape> theShape,
+ const std::vector<int>& theColor) = 0;
+
+ /// Get color from sub shape
+ MODELAPI_EXPORT virtual void getSubShapeColor(const std::shared_ptr<ModelAPI_Result> theResult,
+ const std::shared_ptr<GeomAPI_Shape> theShape,
+ std::vector<int>& theColor) = 0;
+
+ /// Get colored shapes from result
+ MODELAPI_EXPORT virtual void getColoredShapes(const std::shared_ptr<ModelAPI_Result> theResult,
+ std::map<std::shared_ptr<GeomAPI_Shape>, std::vector<int>>& theColoredShapes) = 0;
+
+ /// Forget subshape colors
+ MODELAPI_EXPORT virtual void removeShapeColors(const std::shared_ptr<ModelAPI_Result> theResult) = 0;
+
+ /// Return Attribute selection
+ MODELAPI_EXPORT virtual std::shared_ptr<ModelAPI_AttributeSelection> selection() = 0;
+
/// Set the map of name and color read shape in step file
MODELAPI_EXPORT virtual void setShapeName
(std::map< std::wstring, std::shared_ptr<GeomAPI_Shape> > &theShapeName,
class GeomAPI_Trsf;
#include <string>
+#include <map>
/**\class ModelAPI_ResultPart
* \ingroup DataModel
/// Returns the shape by the name in the part
virtual std::shared_ptr<GeomAPI_Shape> shapeInPart(
const std::wstring& theName, const std::string& theType, int& theIndex) = 0;
+ /// Set color on subshape
+ virtual void setSubShapeColor(const std::shared_ptr<GeomAPI_Shape>& theShape,
+ const std::vector<int>& theColor) = 0;
+
+ /// Get subshape color
+ virtual void getSubShapeColor(const std::shared_ptr<GeomAPI_Shape>& theShape,
+ std::vector<int>& theColor) = 0;
+
+ /// Get colored shapes from result
+ virtual void getColoredShapes(std::map<std::shared_ptr<GeomAPI_Shape>,
+ std::vector<int>>&theColoredShapes) = 0;
+
+ /// Forget subshape colors
+ virtual void removeShapeColors() = 0;
/// Updates the selection inside of the part as a geometrical selection
virtual bool combineGeometrical(const int theIndex, std::wstring& theNewName) = 0;
/// Updates the shape-result of the part (called on Part feature execution)
virtual void updateShape() = 0;
+ /// Return Attribute selection
+ virtual std::shared_ptr<ModelAPI_AttributeSelection> selection() = 0;
+
/// Loading the part from file
virtual void loadPart() = 0;
};
return ResultBodyPtr(); // not found
}
+ResultBodyPtr mainBody(const ResultBodyPtr theSubBody)
+{
+ ResultBodyPtr aBody = theSubBody;
+ while (aBody.get())
+ { // get the top-most main
+ ResultBodyPtr aNextBody = bodyOwner(aBody);
+ if (aNextBody.get())
+ aBody = aNextBody;
+ else break;
+ }
+ return aBody;
+}
+
int bodyIndex(const ResultPtr& theSub)
{
int anIndex = -1;
aColorAttr->setValue(0, theColor[0]);
aColorAttr->setValue(1, theColor[1]);
aColorAttr->setValue(2, theColor[2]);
+ removeShapeColors(theResult);
}
}
+void setColor(ResultPtr theResult, GeomShapePtr theShape, const std::vector<int>& theColor)
+{
+ if (!theResult.get() || theShape->isNull())
+ return;
+ if (!theResult->shape()->isSubShape(theShape))
+ return;
+
+ ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+ if (aBody.get())
+ {
+ aBody = mainBody(aBody);
+ aBody->setSubShapeColor(theResult, theShape, theColor);
+ }
+ else
+ {
+ ResultPartPtr aResPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theResult);
+ if (!aResPart.get())
+ return;
+ aResPart->setSubShapeColor(theShape, theColor);
+ }
+
+ static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
+ ModelAPI_EventCreator::get()->sendUpdated(theResult, anEvent);
+}
+
+
void getColor(const std::shared_ptr<ModelAPI_Result>& theResult, std::vector<int>& theColor)
{
theColor.clear();
}
}
+void getColor(const ResultPtr theResult, const GeomShapePtr theShape, std::vector<int>& theColor)
+{
+ theColor.clear();
+ if (!theResult.get() || theShape->isNull())
+ return;
+ if (!theResult->shape()->isSubShape(theShape))
+ return;
+
+ ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+ if (aBody.get())
+ {
+ aBody = mainBody(aBody);
+ aBody->getSubShapeColor(theResult, theShape, theColor);
+ }
+ else
+ {
+ ResultPartPtr aResPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theResult);
+ if (!aResPart.get())
+ return;
+ aResPart->getSubShapeColor(theShape, theColor);
+ }
+}
+
+void getColoredShapes(const ResultPtr theResult,
+ std::map<GeomShapePtr, std::vector<int>>& theColoredShapes,
+ bool theGetSubResults)
+{
+ if (!theResult.get())
+ return;
+
+ ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+ if (aBody.get())
+ {
+ ResultBodyPtr aMainBody = mainBody(aBody);
+ if (!aMainBody.get())
+ return;
+ if (theGetSubResults)
+ {
+ std::list<ResultPtr> aSubResults;
+ allSubs(aBody, aSubResults);
+ for (std::list<ResultPtr>::iterator anIt = aSubResults.begin();
+ anIt != aSubResults.end(); ++anIt)
+ {
+ aMainBody->getColoredShapes(*anIt, theColoredShapes);
+ }
+ }
+
+ aMainBody->getColoredShapes(theResult, theColoredShapes);
+ }
+ else
+ {
+ ResultPartPtr aResPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theResult);
+ if (!aResPart.get())
+ return;
+ aResPart->getColoredShapes(theColoredShapes);
+ }
+}
+
+void removeShapeColors(const std::shared_ptr<ModelAPI_Result> theResult)
+{
+ if (!theResult.get())
+ return;
+
+ ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+ if (aBody.get())
+ {
+ aBody = mainBody(aBody);
+ aBody->removeShapeColors(theResult);
+ }
+ else
+ {
+ ResultPartPtr aResPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(theResult);
+ if (!aResPart.get())
+ return;
+ aResPart->removeShapeColors();
+ }
+}
+
//******************************************************
void getIsoLines(const std::shared_ptr<ModelAPI_Result>& theResult,
bool& isVisible, std::vector<int>& theNbLines)
*/
MODELAPI_EXPORT std::shared_ptr<ModelAPI_ResultBody>
bodyOwner(const std::shared_ptr<ModelAPI_Result>& theSub, const bool theRoot = false);
+
+/*
+* Returns the result - main parent of this result.
+* \param theSubBody the sub-element of composit result
+* \returns Root resultBody
+*/
+MODELAPI_EXPORT std::shared_ptr<ModelAPI_ResultBody> mainBody(const std::shared_ptr<ModelAPI_ResultBody> theSubBody);
+
/*!
* Returns index of this result in parent (if parent exists, returned by bodyOwner)
* \returns zero-base index, or -1 if not found
MODELAPI_EXPORT void getColor(const std::shared_ptr<ModelAPI_Result>& theResult,
std::vector<int>& theColor);
+/*! Returns current color of the current subShape
+* \param[in] theResult a result object
+* \param[in] theShape a shape that belongs result object
+* \param[out] theColor a color values if it is defined
+*/
+MODELAPI_EXPORT void getColor(const std::shared_ptr<ModelAPI_Result> theResult,
+ const std::shared_ptr<GeomAPI_Shape> theShape,
+ std::vector<int>& theColor);
+
+/*! Returns colored shapes of the result
+* \param[in] theResult a result object
+* \param[out] theColoredShapes a set which contans all colored shapes of the result
+* \param[in] theSubResult true - get colored shapes from subresults,
+* else - get colored shaped only from result
+*/
+MODELAPI_EXPORT void getColoredShapes(const std::shared_ptr<ModelAPI_Result> theResult,
+ std::map<std::shared_ptr<GeomAPI_Shape>, std::vector<int>>& theColoredShapes,
+ bool theGetSubResults = false);
+
+/*! Remove all subshape color from result
+* Need, when we set color on result
+* \param[in] theResult a result object
+*/
+MODELAPI_EXPORT void removeShapeColors(const std::shared_ptr<ModelAPI_Result> theResult);
+
/*! Set color of the result
* \param[in] theResult a result object
* \param[in] theColor a color values
MODELAPI_EXPORT void setColor(std::shared_ptr<ModelAPI_Result> theResult,
const std::vector<int>& theColor);
+/*! Set color of the shape from result
+* \param[in] theResult a result object
+* \param[in] theShape a shape that belongs result object
+* \param[in] theColor a color values
+*/
+MODELAPI_EXPORT void setColor(std::shared_ptr<ModelAPI_Result> theResult,
+ std::shared_ptr<GeomAPI_Shape> theShape,
+ const std::vector<int>& theColor);
+
/*! Returns number of iso-lines of the current result
* \param[in] theResult a result object
* \param[out] theNbLines values of iso-lines
bool aRes = process(aSubDoc);
if (isDumpModelDo)
*this << "\nmodel.do()\n";
+ std::map<GeomShapePtr, std::vector<int>> aColoredShapes;
+ ModelAPI_Tools::getColoredShapes(aPartResult, aColoredShapes, true);
+ if (!aColoredShapes.empty())
+ *this << "\n";
+ for (std::map<GeomShapePtr, std::vector<int>>::const_iterator anIter(aColoredShapes.cbegin());
+ anIter != aColoredShapes.cend(); ++anIter)
+ {
+ GeomShapePtr aShape = anIter->first;
+
+ *this << aPartName << ".result()";
+ *this << ".setColor(model.selection(\"" << aShape->shapeTypeStr() << "\", \""
+ << Locale::Convert::toString((aPartResult)->data()->name(aShape)) << "\"), "
+ << anIter->second.at(0) << ", " << anIter->second.at(1)
+ << ", " << anIter->second.at(2) << ")\n";
+ }
*this << std::endl;
return aRes;
}
<< ", " << aColor->value(2) << ")\n";
}
}
+ // set subresult color
+ if ((isParentResult(*aResIt)) && hasColoredShape(*aResIt, true))
+ {
+ std::map<GeomShapePtr, std::vector<int>> aColoredShapes;
+ ModelAPI_Tools::getColoredShapes(*aResIt, aColoredShapes, true);
+
+ for (std::map<GeomShapePtr, std::vector<int>>::const_iterator anIter(aColoredShapes.cbegin());
+ anIter != aColoredShapes.cend(); ++anIter)
+ {
+ GeomShapePtr aShape = anIter->first;
+
+ *this << *aResIt;
+ *myDumpStorage << ".setColor(model.selection(\"" << aShape->shapeTypeStr() << "\", \""
+ << Locale::Convert::toString((*aResIt)->data()->name(aShape)) << "\"), "
+ << anIter->second.at(0) << ", " << anIter->second.at(1)
+ << ", " << anIter->second.at(2) << ")\n";
+ }
+ }
// set result deflection
if (!isDefaultDeflection(*aResIt)) {
AttributeDoublePtr aDeflectionAttr =
return anOwner && anOwner->getKind() == SKETCH;
}
+bool ModelHighAPI_Dumper::hasColoredShape(const ResultPtr& theResult, bool theGetSubResults) const
+{
+ std::map<GeomShapePtr, std::vector<int>> aColoredShapes;
+ ModelAPI_Tools::getColoredShapes(theResult, aColoredShapes, theGetSubResults);
+ return !aColoredShapes.empty();
+}
+
+bool ModelHighAPI_Dumper::isParentResult(const ResultPtr& theResult) const
+{
+ ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theResult);
+ ResultBodyPtr aMainBody = ModelAPI_Tools::mainBody(aResBody);
+
+ if (aMainBody.get() && aResBody == aMainBody)
+ return true;
+
+ return false;
+}
+
bool ModelHighAPI_Dumper::isDefaultColor(const ResultPtr& theResult) const
{
AttributeIntArrayPtr aColor = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
ModelAPI_Tools::allResults(theEntity, allRes);
for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
if(!myNames[*aRes].myIsDefault || !isDefaultColor(*aRes) ||
- !isDefaultDeflection(*aRes) || !isDefaultTransparency(*aRes))
+ !isDefaultDeflection(*aRes) || !isDefaultTransparency(*aRes) ||
+ (isParentResult(*aRes) && hasColoredShape(*aRes, true)))
aResultsWithNameOrColor.push_back(*aRes);
}
// store just dumped entity to stack
/// Stores names of results for the given feature
void saveResultNames(const FeaturePtr& theFeature);
+ /// Check the result feature has colored shape
+ bool hasColoredShape(const ResultPtr& theResult, bool theGetSubResults = false) const;
+
+ /// Check the result is parent result int the feature
+ bool isParentResult(const ResultPtr& theResult) const;
+
/// Check the result feature has default color
bool isDefaultColor(const ResultPtr& theResult) const;
#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_Feature.h>
#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultPart.h>
#include <ModelAPI_Tools.h>
#include <GeomAPI_Pnt.h>
}
}
+void ModelHighAPI_Selection::setColor(const ModelHighAPI_Selection& theShape,
+ int theRed, int theGreen, int theBlue)
+{
+ if (myVariantType != VT_ResultSubShapePair || !myResultSubShapePair.first.get())
+ return;
+ std::vector<int> aColor({ theRed, theGreen, theBlue });
+ std::shared_ptr<GeomAPI_Shape> aShape = myResultSubShapePair.second;
+ ResultBodyPtr aResBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(
+ myResultSubShapePair.first);
+
+ ResultPtr aRes;
+ AttributeSelectionPtr aSelAttr;
+ if (aResBody.get())
+ {
+ aSelAttr = aResBody->selection();
+ theShape.fillAttribute(aSelAttr);
+ }
+ else
+ {
+ std::wstring aSubShapeName = theShape.myTypeSubShapeNamePair.second;
+ aSubShapeName = changePartName(theShape, aSubShapeName);
+ ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(myResultSubShapePair.first);
+ aSelAttr = aPart->selection();
+ aSelAttr->selectSubShape(myTypeSubShapeNamePair.first, aSubShapeName);
+ }
+ aRes = aSelAttr->context();
+ aShape = aSelAttr->value();
+ if (aRes.get() && aShape.get() && !aShape->isNull())
+ ModelAPI_Tools::setColor(aRes, aShape, aColor);
+}
+
void ModelHighAPI_Selection::setDeflection(double theValue)
{
if (myVariantType != VT_ResultSubShapePair || !myResultSubShapePair.first.get())
ResultBodyPtr aResult = aBody->subResult(theIndex);
return ModelHighAPI_Selection(aResult, aResult->shape());
}
+
+std::wstring ModelHighAPI_Selection::changePartName(const ModelHighAPI_Selection& theShape, const std::wstring& theName)
+{
+ std::shared_ptr<GeomAPI_Shape> aShape;
+ int index;
+ ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(myResultSubShapePair.first);
+
+ std::size_t aPartEnd = theName.find(L'/');
+ if (aPartEnd == std::wstring::npos)
+ return std::wstring();
+ aShape = aPart->shapeInPart(theName.substr(aPartEnd + 1), theShape.myTypeSubShapeNamePair.first, index);
+ std::wstring name = aPart->data()->name(aShape);
+ return name;
+}
\ No newline at end of file
MODELHIGHAPI_EXPORT
void setColor(int theRed = 0, int theGreen = 0, int theBlue = 0, bool random = false);
+ /// Change subShape' color
+ MODELHIGHAPI_EXPORT
+ void setColor(const ModelHighAPI_Selection& theShape, int theRed, int theGreen, int theBlue);
+
/// Change result's deflection
MODELHIGHAPI_EXPORT
void setDeflection(double theValue);
MODELHIGHAPI_EXPORT
ModelHighAPI_Selection subResult(int theIndex) const;
+private:
+ /// Returns new part for shape
+ MODELHIGHAPI_EXPORT
+ std::wstring changePartName(const ModelHighAPI_Selection& theShape, const std::wstring& theName);
+
protected:
VariantType myVariantType;
ResultSubShapePair myResultSubShapePair;
/// Returns list of currently selected results
virtual QObjectPtrList selectedPresentations() const = 0;
+ /// Returns map of selected results and their selected subobjects
+ virtual QMap<ResultPtr, QList<GeomShapePtr>> selectedObjectsAndSubObjects() const = 0;
+
/// Returns list of currently selected QModelIndexes
virtual QModelIndexList selectedIndexes() const = 0;
#include <GeomAdaptor_Curve.hxx>
#include <TopExp.hxx>
#include <GCPnts_AbscissaPoint.hxx>
+#include <TopExp_Explorer.hxx>
#if OCC_VERSION_HEX > 0x070400
#include <StdPrs_ToolTriangulatedShape.hxx>
}
// change deviation coefficient to provide more precise circle
try {
- AIS_Shape::Compute(thePresentationManager, thePresentation, theMode);
+ ViewerData_AISShape::Compute(thePresentationManager, thePresentation, theMode);
}
catch (...) {
return;
<source>No visualization</source>
<translation>Aucune visualisation</translation>
</message>
+ <message>
+ <source>Set color on subshape of result</source>
+ <translation>Définir la couleur sur la sous - forme du résultat</translation>
+ </message>
</context>
</TS>
Config_PropManager::registerProp("Visualization", "axis_arrow_size",
"Trihedron arrows constant size", Config_Prop::IntSpin, "10");
+ Config_PropManager::registerProp("Visualization", "color_subshape_result",
+ "Set color on subshape of result", Config_Prop::Boolean, "true");
+
Config_PropManager::registerProp("Shortcuts", "add_parameter_shortcut",
"Add parameter in parameters manager dialog",
Config_Prop::Shortcut, "Ctrl+A");
PartSet_Tools::getDefaultColor(aResult, false, aColor);
}
thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+
+ std::map<GeomShapePtr, std::vector<int>> aColoredShapes;
+ ModelAPI_Tools::getColoredShapes(aResult, aColoredShapes);
+ if (!aColoredShapes.empty()) {
+ for (std::map<GeomShapePtr, std::vector<int>>::const_iterator anIter(aColoredShapes.cbegin());
+ anIter != aColoredShapes.cend(); ++anIter) {
+ thePrs->setColor(anIter->first, anIter->second.at(0),
+ anIter->second.at(1), anIter->second.at(2));
+ }
+ }
}
}
else {
}
}
-
//******************************************************
ObjectPtr PartSet_Module::findPresentedObject(const AISObjectPtr& theAIS) const
{
#include <Events_Loop.h>
#include <ModelAPI_Events.h>
#include <Config_PropManager.h>
+#include <TopExp_Explorer.hxx>
#include <set>
aCol(aColor[0] / 255., aColor[1] / 255., aColor[2] / 255., Quantity_TOC_RGB);
aAISIO->SetColor(aCol);
}
+ // Set color on subshape from result
+ std::map<GeomShapePtr, std::vector<int>> aColoredShapes;
+ ModelAPI_Tools::getColoredShapes(aResult, aColoredShapes);
+ Handle(AIS_ColoredShape) aResShape = Handle(AIS_ColoredShape)::DownCast(aAISIO);
+ Handle(ModuleBase_ResultPrs) aResPrsShape = Handle(ModuleBase_ResultPrs)::DownCast(aResShape);
+
+ if (!aColoredShapes.empty() && !aResPrsShape.IsNull())
+ {
+ for (std::map<GeomShapePtr, std::vector<int>>::const_iterator anIter(aColoredShapes.cbegin());
+ anIter != aColoredShapes.cend(); ++anIter)
+ {
+ if (aAISObj->getShape()->isSubShape(anIter->first))
+ {
+ Quantity_Color aColorQ(anIter->second.at(0) / 255.,
+ anIter->second.at(1) / 255.,
+ anIter->second.at(2) / 255.,
+ Quantity_TOC_RGB);
+ aResPrsShape->SetCustomColor(anIter->first->impl<TopoDS_Shape>(), aColorQ);
+ }
+ }
+ }
+ else
+ {
+ aResShape->ClearCustomAspects();
+ }
// Set deflection
double aDeflection = ModelAPI_Tools::getDeflection(aResult);
if ((aDeflection >= 0) && (aDeflection != aAISObj->getDeflection()))
return aSelectedList;
}
+QMap<ResultPtr, QList<GeomShapePtr>> XGUI_Selection::selectedObjectsAndSubObjects() const
+{
+ QMap<ResultPtr, QList<GeomShapePtr>> aSelectedObjects;
+
+ // Add all objects, which selected in Viewer
+ QList<ModuleBase_ViewerPrsPtr> aValues = getSelected(ModuleBase_ISelection::Viewer);
+ foreach(ModuleBase_ViewerPrsPtr aPrs, aValues)
+ {
+ ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(aPrs->object());
+ GeomShapePtr aShape = aPrs->shape();
+
+ aSelectedObjects[aResult].push_back(aShape);
+ }
+
+ // Add object, which selected in browser, but not selected in Viewer
+ QObjectPtrList anObjects = selectedObjects();
+ foreach(ObjectPtr anObject, anObjects)
+ {
+ ResultBodyPtr aResultBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(anObject);
+ if (!aResultBody.get())
+ continue;
+ GeomShapePtr aBodyShape = aResultBody->shape();
+
+ if (aSelectedObjects.contains(aResultBody))
+ continue;
+ bool isContains = false;
+ foreach(GeomShapePtr aCurShape, aSelectedObjects[aResultBody])
+ {
+ if (aCurShape->impl<TopoDS_Shape>().IsEqual(aBodyShape->impl<TopoDS_Shape>()))
+ {
+ isContains = true;
+ break;
+ }
+ }
+ if (!isContains)
+ aSelectedObjects[aResultBody].push_back(aBodyShape);
+ }
+ return aSelectedObjects;
+}
+
//**************************************************************
QModelIndexList XGUI_Selection::selectedIndexes() const
{
/// Returns list of currently selected results
virtual QObjectPtrList selectedPresentations() const;
+ /// Returns map of selected results and their selected subobjects
+ virtual QMap<ResultPtr, QList<GeomShapePtr>> selectedObjectsAndSubObjects() const;
+
/// Returns list of currently selected QModelIndexes
virtual QModelIndexList selectedIndexes() const;
void XGUI_Workshop::onContextMenuCommand(const QString& theId, bool isChecked)
{
QObjectPtrList anObjects = mySelector->selection()->selectedObjects();
+ QMap<ResultPtr, QList<GeomShapePtr>> aSelectedObjects = mySelector->selection()->selectedObjectsAndSubObjects();
if (theId == "DELETE_CMD")
deleteObjects();
else if (theId == "CLEAN_HISTORY_CMD")
else if (theId == "RECOVER_CMD")
recoverFeature();
else if (theId == "COLOR_CMD")
- changeColor(anObjects);
+ changeColor(aSelectedObjects);
else if (theId == "AUTOCOLOR_CMD")
- changeAutoColor(anObjects);
+ changeAutoColor(aSelectedObjects);
else if (theId == "ISOLINES_CMD")
changeIsoLines(anObjects);
else if (theId == "SHOW_ISOLINES_CMD") {
}
//**************************************************************
-void XGUI_Workshop::changeColor(const QObjectPtrList& theObjects)
+void XGUI_Workshop::changeColor(const QMap<ResultPtr, QList<GeomShapePtr>>& theSelectedObjects)
{
AttributeIntArrayPtr aColorAttr;
// 1. find the current color of the object. This is a color of AIS presentation
// The objects are iterated until a first valid color is found
std::vector<int> aColor;
- foreach(ObjectPtr anObject, theObjects) {
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
- if (aResult.get()) {
- ModelAPI_Tools::getColor(aResult, aColor);
+ QList<ModuleBase_ViewerPrsPtr> aValues = mySelector->selection()->getSelected(ModuleBase_ISelection::Viewer);
+ const bool isColorOnSubShape = Config_PropManager::boolean("Visualization", "color_subshape_result");
+ foreach(ResultPtr aResult, theSelectedObjects.keys())
+ {
+ if (!aResult.get())
+ continue;
+
+ foreach(GeomShapePtr aShape, theSelectedObjects[aResult])
+ {
+ if (aResult->shape()->impl<TopoDS_Shape>().IsEqual(aShape->impl<TopoDS_Shape>()) || !isColorOnSubShape)
+ {
+ ModelAPI_Tools::getColor(aResult, aColor);
+ }
+ else if (!aShape->isNull())
+ {
+ ModelAPI_Tools::getColor(aResult, aShape, aColor);
+ if (aColor.empty())
+ {
+ ModelAPI_Tools::getColor(aResult, aColor);
+ }
+ }
+
if (aColor.empty()) {
- AISObjectPtr anAISObj = myDisplayer->getAISObject(anObject);
+ AISObjectPtr anAISObj = myDisplayer->getAISObject(aResult);
if (anAISObj.get()) {
aColor.resize(3);
anAISObj->getColor(aColor[0], aColor[1], aColor[2]);
}
}
- if (aColor.empty()) {
+ if (aColor.empty())
getDefaultColor(aResult, false, aColor);
- }
+ if (!aColor.empty() || !isColorOnSubShape)
+ break;
}
+
+ if (!aColor.empty())
+ break;
}
+
if (aColor.size() != 3)
return;
aMgr->startOperation(aDescription.toStdString());
- // 4. set the value to all results
+ // 4. set the value to all results and subshapes from result (if was select subshape of result)
std::vector<int> aColorResult = aDlg->getColor();
- foreach(ObjectPtr anObj, theObjects) {
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
- if (aResult.get() != NULL) {
- ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
- if (aBodyResult.get() != NULL) { // change colors for all sub-solids
- std::list<ResultPtr> allRes;
- ModelAPI_Tools::allSubs(aBodyResult, allRes);
- for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
- ModelAPI_Tools::setColor(*aRes, !isRandomColor ? aColorResult : aDlg->getRandomColor());
+ foreach(ResultPtr aResult, theSelectedObjects.keys())
+ {
+ if (!aResult.get())
+ continue;
+ ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
+ foreach(GeomShapePtr aShape, theSelectedObjects[aResult])
+ {
+ if (aResult->shape()->impl<TopoDS_Shape>().IsEqual(aShape->impl<TopoDS_Shape>()) || !isColorOnSubShape)
+ {
+ if (aResult.get() != NULL)
+ {
+ // change colors for all sub-solids
+ std::list<ResultPtr> allRes;
+ ModelAPI_Tools::allSubs(aBodyResult, allRes);
+ for (std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++)
+ {
+ ModelAPI_Tools::setColor(*aRes, !isRandomColor ? aColorResult : aDlg->getRandomColor());
+ }
+ ModelAPI_Tools::setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
}
+ if (!isColorOnSubShape)
+ break;
+ }
+ else if (!aShape->isNull())
+ {
+ ModelAPI_Tools::setColor(aResult, aShape, !isRandomColor ? aColorResult : aDlg->getRandomColor());
}
- ModelAPI_Tools::setColor(aResult, !isRandomColor ? aColorResult : aDlg->getRandomColor());
}
}
+
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
aMgr->finishOperation();
updateCommandStatus();
}
//**************************************************************
-void XGUI_Workshop::changeAutoColor(const QObjectPtrList& theObjects)
+void XGUI_Workshop::changeAutoColor(const QMap<ResultPtr, QList<GeomShapePtr>>& theSelectedObjects)
{
if (!abortAllOperations())
return;
Config_PropManager::setAutoColorStatus(false);
ModelAPI_Tools::findRandomColor(aColor, true);
} else {
- // set the value to all results
- foreach (ObjectPtr anObj, theObjects) {
- DocumentPtr aDocument = anObj->document();
+ QList<ModuleBase_ViewerPrsPtr> aValues = mySelector->selection()->getSelected(ModuleBase_ISelection::Viewer);
+ const bool isColorOnSubShape = Config_PropManager::boolean("Visualization", "color_subshape_result");
+ foreach(ResultPtr aResult, theSelectedObjects.keys())
+ {
+ if (!aResult.get())
+ continue;
+
+ DocumentPtr aDocument = aResult->document();
std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
- // find the object iterator
- std::list<FeaturePtr>::iterator anObjectIt = anAllFeatures.begin();
- for (; anObjectIt != anAllFeatures.end(); ++ anObjectIt) {
- FeaturePtr aFeature = *anObjectIt;
- if (aFeature.get()) {
- std::list<ResultPtr> aResults;
- ModelAPI_Tools::allResults(aFeature, aResults);
- std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
- for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
- ResultPtr aGroupResult = *aIt;
- if (aGroupResult.get() &&
+ foreach(GeomShapePtr aShape, theSelectedObjects[aResult])
+ {
+ std::list<FeaturePtr>::iterator anObjectIt = anAllFeatures.begin();
+ for (; anObjectIt != anAllFeatures.end(); ++anObjectIt) {
+ FeaturePtr aFeature = *anObjectIt;
+ if (aFeature.get()) {
+ std::list<ResultPtr> aResults;
+ ModelAPI_Tools::allResults(aFeature, aResults);
+ std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
+ for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
+ ResultPtr aGroupResult = *aIt;
+ if (aGroupResult.get() &&
aGroupResult->groupName() == ModelAPI_ResultGroup::group()) {
- ModelAPI_Tools::findRandomColor(aColor);
- ModelAPI_Tools::setColor(aGroupResult, aColor);
+ ModelAPI_Tools::findRandomColor(aColor);
+ ModelAPI_Tools::setColor(aGroupResult, aColor);
+ }
}
}
}
}
+
+ if (!aColor.empty())
+ break;
}
+
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
aMgr->finishOperation();
updateCommandStatus();
/// \return boolean value
bool canChangeProperty(const QString& theActionName) const;
- /// Change color of the results 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);
+ /// Change color of the selected objects (result and subshape of result) if it is possible
+ /// The operation is available for subshape of result, construction, body and group results
+ /// theSelectedObjects a list of selected objects
+ void changeColor(const QMap<ResultPtr, QList<GeomShapePtr>>& theSelectedObjects);
/// Change Autocolor of the results if it is possible
/// The operation is available for group results
/// theObjects a list of selected objects
- void changeAutoColor(const QObjectPtrList& theObjects);
+ void changeAutoColor(const QMap<ResultPtr, QList<GeomShapePtr>>& theSelectedObjects);
/// Change deflection of the results if it is possible
/// The operation is available for construction, body and group results