1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <Model_ResultGroup.h>
21 #include <Model_Data.h>
22 #include <ModelAPI_AttributeSelectionList.h>
24 #include <GeomAlgoAPI_CompoundBuilder.h>
26 #include <Config_PropManager.h>
28 #include <TDF_Label.hxx>
29 #include <TDF_Reference.hxx>
30 #include <TNaming_Builder.hxx>
31 #include <TNaming_NamedShape.hxx>
32 #include <TopoDS_Shape.hxx>
34 Model_ResultGroup::Model_ResultGroup(std::shared_ptr<ModelAPI_Data> theOwnerData)
36 myOwnerData = theOwnerData;
39 void Model_ResultGroup::colorConfigInfo(std::string& theSection, std::string& theName,
40 std::string& theDefault)
42 theSection = "Visualization";
43 theName = "result_group_color";
44 theDefault = DEFAULT_COLOR();
47 std::shared_ptr<GeomAPI_Shape> Model_ResultGroup::shape()
49 std::shared_ptr<GeomAPI_Shape> aResult;
50 // obtain stored shape
51 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
52 if (aData && aData->isValid()) {
53 TDF_Label aShapeLab = aData->shapeLab();
54 Handle(TDF_Reference) aRef;
55 if (aShapeLab.FindAttribute(TDF_Reference::GetID(), aRef)) {
56 aShapeLab = aRef->Get();
58 Handle(TNaming_NamedShape) aName;
59 if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
60 TopoDS_Shape aShape = aName->Get();
61 if (!aShape.IsNull()) {
62 aResult.reset(new GeomAPI_Shape);
63 aResult->setImpl(new TopoDS_Shape(aShape));
67 // collect shapes selected in group
68 if (!aResult && myOwnerData) {
69 AttributeSelectionListPtr aList = myOwnerData->selectionList("group_list");
71 std::list<std::shared_ptr<GeomAPI_Shape> > aSubs;
72 for(int a = aList->size() - 1; a >= 0; a--) {
73 std::shared_ptr<GeomAPI_Shape> aSelection = aList->value(a)->value();
74 if (aSelection && !aSelection->isNull()) {
75 aSubs.push_back(aSelection);
79 aResult = GeomAlgoAPI_CompoundBuilder::compound(aSubs);
86 void Model_ResultGroup::store(const GeomShapePtr& theShape)
88 std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
90 TDF_Label aShapeLab = aData->shapeLab();
91 aShapeLab.ForgetAttribute(TDF_Reference::GetID());
92 aShapeLab.ForgetAttribute(TNaming_NamedShape::GetID());
96 TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
98 return; // null shape inside
100 // store the new shape as primitive
101 TNaming_Builder aBuilder(aShapeLab);
102 aBuilder.Generated(aShape);