1 // Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "StudyData_XAO.h"
25 #include <XAO_Group.hxx>
26 #include <XAO_Field.hxx>
27 #include <XAO_Geometry.hxx>
28 #include <XAO_XaoExporter.hxx>
29 #include <XAO_BrepGeometry.hxx>
32 StudyData_XAO::StudyData_XAO() : myExport(NULL), myImport(NULL), myCurrentElementID(0)
35 void StudyData_XAO::SetShape(const long long theShapePtr)
37 myShape = (TopoDS_Shape*)(theShapePtr);
39 myExport = new XAO::Xao();
40 XAO::BrepGeometry* aGeometry = new XAO::BrepGeometry;
41 myExport->setGeometry(aGeometry);
42 aGeometry->setTopoDS_Shape(*myShape);
45 static XAO::Dimension GetDimension(const int theSelType) {
47 case 7: return XAO::VERTEX;
48 case 6: return XAO::EDGE;
49 case 4: return XAO::FACE;
50 case 2: return XAO::SOLID;
51 default: return XAO::WHOLE;
56 int StudyData_XAO::AddGroup(const int theSelType, const std::string theGroupName)
58 XAO::Group* aNewGroup = myExport->addGroup(GetDimension(theSelType), theGroupName);
59 int anID = (int)myGroups.size();
60 myGroups[anID] = aNewGroup;
64 void StudyData_XAO::AddGroupSelection(const int theGroupID, const int theSelection)
66 XAO::Group* aGroup = myGroups[theGroupID];
67 aGroup->add(theSelection);
70 void StudyData_XAO::Export(const std::string theFileName)
72 myExport->setAuthor("ShaperStudy");
74 XAO::XaoExporter::saveToFile(myExport, theFileName, "");
77 int StudyData_XAO::AddField(const int theValType, const int theSelType,
78 const int theCompsNum, const std::string theFieldName)
80 XAO::Field* aNewField = myExport->addField(
81 XAO::Type(theValType), GetDimension(theSelType), theCompsNum, theFieldName);
82 int anID = (int)myFields.size();
83 myFields[anID] = aNewField;
87 void StudyData_XAO::SetFieldComponent(const int theFieldID, const int theCompIndex,
88 const std::string theCompName)
90 myFields[theFieldID]->setComponentName(theCompIndex, theCompName);
93 void StudyData_XAO::AddStep(const int theFieldID, const int theStepID, const int theStampID)
95 XAO::Step* aNewStep = myFields[theFieldID]->addNewStep(theStepID);
96 aNewStep->setStamp(theStampID);
97 if (mySteps.find(theFieldID) == mySteps.end())
98 mySteps[theFieldID] = std::map<int, XAO::Step*>();
99 mySteps[theFieldID][theStepID] = aNewStep;
100 myCurrentElementID = 0;
103 void StudyData_XAO::AddStepValue(
104 const int theFieldID, const int theStepID, std::string theValue)
106 int aColumns = myFields[theFieldID]->countComponents();
107 mySteps[theFieldID][theStepID]->setStringValue(
108 myCurrentElementID / aColumns, myCurrentElementID % aColumns, theValue);
109 myCurrentElementID++;
112 std::string StudyData_XAO::Import(const std::string theFileName)
115 myImport = new XAO::Xao();
117 if (XAO::XaoExporter::readFromFile(theFileName, myImport)) {
118 XAO::Geometry* aGeometry = myImport->getGeometry();
119 XAO::Format aFormat = aGeometry->getFormat();
120 if (aFormat == XAO::BREP) {
121 if (XAO::BrepGeometry* aBrepGeometry = dynamic_cast<XAO::BrepGeometry*>(aGeometry))
122 myShape = new TopoDS_Shape(aBrepGeometry->getTopoDS_Shape());
124 anError = "Unsupported XAO geometry format:" + XAO::XaoUtils::shapeFormatToString(aFormat);
127 anError = "XAO object was not read successful";
129 } catch (XAO::XAO_Exception& e) {
136 long long StudyData_XAO::GetShape()
138 return (long long)(myShape);
141 static int GetSelectionType(const XAO::Dimension theDimension) {
142 switch(theDimension) {
143 case XAO::VERTEX: return 7;
144 case XAO::EDGE: return 6;
145 case XAO::FACE: return 4;
146 case XAO::SOLID: return 2;
152 int StudyData_XAO::GetGroupDimension(const int theGroupID)
154 XAO::Group* aXaoGroup = myImport->getGroup(theGroupID);
155 return GetSelectionType(aXaoGroup->getDimension());
158 std::list<long> StudyData_XAO::GetGroupSelection(const int theGroupID)
160 XAO::Group* aXaoGroup = myImport->getGroup(theGroupID);
161 std::list<long> aResult;
162 for (int anElementIndex = 0; anElementIndex < aXaoGroup->count(); ++anElementIndex) {
163 aResult.push_back(aXaoGroup->get(anElementIndex));
168 int StudyData_XAO::GetValuesType(const int theFieldID)
170 XAO::Field* aField = myImport->getField(theFieldID);
171 return (int)(aField->getType());
174 int StudyData_XAO::GetSelectionType(const int theFieldID)
176 XAO::Field* aField = myImport->getField(theFieldID);
177 return GetSelectionType(aField->getDimension());
180 std::list<std::string> StudyData_XAO::GetComponents(const int theFieldID)
182 XAO::Field* aField = myImport->getField(theFieldID);
183 std::list<std::string> aResult;
184 int aNum = aField->countComponents();
185 for(int a = 0; a < aNum; a++) {
186 aResult.push_back(aField->getComponentName(a));
191 void StudyData_XAO::BeginSteps(const int theFieldID)
193 myStepIterator = myImport->getField(theFieldID)->begin();
196 bool StudyData_XAO::More(const int theFieldID)
198 return myStepIterator != myImport->getField(theFieldID)->end();
201 void StudyData_XAO::Next()
206 int StudyData_XAO::GetStamp()
208 return (*myStepIterator)->getStamp();
211 int StudyData_XAO::GetStepIndex()
213 return (*myStepIterator)->getStep();
216 std::list<std::string> StudyData_XAO::GetValues()
218 std::list<std::string> aResult;
219 int aComps = (*myStepIterator)->countComponents();
220 int aVals = (*myStepIterator)->countValues();
221 for(int a = 0; a < aVals; a++) {
222 aResult.push_back((*myStepIterator)->getStringValue(a / aComps, a % aComps));