1 // Copyright (C) 2019-2020 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 "StudyData_XAO.h"
22 #include <XAO_Group.hxx>
23 #include <XAO_Field.hxx>
24 #include <XAO_Geometry.hxx>
25 #include <XAO_XaoExporter.hxx>
26 #include <XAO_BrepGeometry.hxx>
29 StudyData_XAO::StudyData_XAO() : myExport(NULL), myImport(NULL), myCurrentElementID(0)
32 void StudyData_XAO::SetShape(const long long theShapePtr)
34 myShape = (TopoDS_Shape*)(theShapePtr);
36 myExport = new XAO::Xao();
37 XAO::BrepGeometry* aGeometry = new XAO::BrepGeometry;
38 myExport->setGeometry(aGeometry);
39 aGeometry->setTopoDS_Shape(*myShape);
42 static XAO::Dimension GetDimension(const int theSelType) {
44 case 7: return XAO::VERTEX;
45 case 6: return XAO::EDGE;
46 case 4: return XAO::FACE;
47 case 2: return XAO::SOLID;
48 default: return XAO::WHOLE;
53 int StudyData_XAO::AddGroup(const int theSelType, const std::string theGroupName)
55 XAO::Group* aNewGroup = myExport->addGroup(GetDimension(theSelType), theGroupName);
56 int anID = (int)myGroups.size();
57 myGroups[anID] = aNewGroup;
61 void StudyData_XAO::AddGroupSelection(const int theGroupID, const int theSelection)
63 XAO::Group* aGroup = myGroups[theGroupID];
64 aGroup->add(theSelection);
67 void StudyData_XAO::Export(const std::string theFileName)
69 myExport->setAuthor("ShaperStudy");
71 XAO::XaoExporter::saveToFile(myExport, theFileName, "");
74 int StudyData_XAO::AddField(const int theValType, const int theSelType,
75 const int theCompsNum, const std::string theFieldName)
77 XAO::Field* aNewField = myExport->addField(
78 XAO::Type(theValType), GetDimension(theSelType), theCompsNum, theFieldName);
79 int anID = (int)myFields.size();
80 myFields[anID] = aNewField;
84 void StudyData_XAO::SetFieldComponent(const int theFieldID, const int theCompIndex,
85 const std::string theCompName)
87 myFields[theFieldID]->setComponentName(theCompIndex, theCompName);
90 void StudyData_XAO::AddStep(const int theFieldID, const int theStepID, const int theStampID)
92 XAO::Step* aNewStep = myFields[theFieldID]->addNewStep(theStepID);
93 aNewStep->setStamp(theStampID);
94 if (mySteps.find(theFieldID) == mySteps.end())
95 mySteps[theFieldID] = std::map<int, XAO::Step*>();
96 mySteps[theFieldID][theStepID] = aNewStep;
97 myCurrentElementID = 0;
100 void StudyData_XAO::AddStepValue(
101 const int theFieldID, const int theStepID, std::string theValue)
103 int aColumns = myFields[theFieldID]->countComponents();
104 mySteps[theFieldID][theStepID]->setStringValue(
105 myCurrentElementID / aColumns, myCurrentElementID % aColumns, theValue);
106 myCurrentElementID++;
109 std::string StudyData_XAO::Import(const std::string theFileName)
112 myImport = new XAO::Xao();
114 if (XAO::XaoExporter::readFromFile(theFileName, myImport)) {
115 XAO::Geometry* aGeometry = myImport->getGeometry();
116 XAO::Format aFormat = aGeometry->getFormat();
117 if (aFormat == XAO::BREP) {
118 if (XAO::BrepGeometry* aBrepGeometry = dynamic_cast<XAO::BrepGeometry*>(aGeometry))
119 myShape = new TopoDS_Shape(aBrepGeometry->getTopoDS_Shape());
121 anError = "Unsupported XAO geometry format:" + XAO::XaoUtils::shapeFormatToString(aFormat);
124 anError = "XAO object was not read successful";
126 } catch (XAO::XAO_Exception& e) {
133 long long StudyData_XAO::GetShape()
135 return (long long)(myShape);
138 static int GetSelectionTypeInt(const XAO::Dimension theDimension) {
139 switch(theDimension) {
140 case XAO::VERTEX: return 7;
141 case XAO::EDGE: return 6;
142 case XAO::FACE: return 4;
143 case XAO::SOLID: return 2;
149 int StudyData_XAO::GetGroupDimension(const int theGroupID)
151 XAO::Group* aXaoGroup = myImport->getGroup(theGroupID);
152 return GetSelectionTypeInt(aXaoGroup->getDimension());
155 std::list<long> StudyData_XAO::GetGroupSelection(const int theGroupID)
157 XAO::Group* aXaoGroup = myImport->getGroup(theGroupID);
158 std::list<long> aResult;
159 for (int anElementIndex = 0; anElementIndex < aXaoGroup->count(); ++anElementIndex) {
160 aResult.push_back(aXaoGroup->get(anElementIndex));
165 int StudyData_XAO::GetValuesType(const int theFieldID)
167 XAO::Field* aField = myImport->getField(theFieldID);
168 return (int)(aField->getType());
171 int StudyData_XAO::GetSelectionType(const int theFieldID)
173 XAO::Field* aField = myImport->getField(theFieldID);
174 return GetSelectionTypeInt(aField->getDimension());
177 std::list<std::string> StudyData_XAO::GetComponents(const int theFieldID)
179 XAO::Field* aField = myImport->getField(theFieldID);
180 std::list<std::string> aResult;
181 int aNum = aField->countComponents();
182 for(int a = 0; a < aNum; a++) {
183 aResult.push_back(aField->getComponentName(a));
188 void StudyData_XAO::BeginSteps(const int theFieldID)
190 myStepIterator = myImport->getField(theFieldID)->begin();
193 bool StudyData_XAO::More(const int theFieldID)
195 return myStepIterator != myImport->getField(theFieldID)->end();
198 void StudyData_XAO::Next()
203 int StudyData_XAO::GetStamp()
205 return (*myStepIterator)->getStamp();
208 int StudyData_XAO::GetStepIndex()
210 return (*myStepIterator)->getStep();
213 std::list<std::string> StudyData_XAO::GetValues()
215 std::list<std::string> aResult;
216 int aComps = (*myStepIterator)->countComponents();
217 int aVals = (*myStepIterator)->countValues();
218 for(int a = 0; a < aVals; a++) {
219 aResult.push_back((*myStepIterator)->getStringValue(a / aComps, a % aComps));