1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "DriverUNV_W_SMDS_Mesh.h"
24 #include "SMDS_Mesh.hxx"
25 #include "SMESHDS_GroupBase.hxx"
26 //#include "SMESH_Group.hxx"
27 #include "SMDS_QuadraticEdge.hxx"
28 #include "SMDS_QuadraticFaceOfNodes.hxx"
30 #include "utilities.h"
32 #include "UNV2411_Structure.hxx"
33 #include "UNV2412_Structure.hxx"
34 #include "UNV2417_Structure.hxx"
35 #include "UNV_Utilities.hxx"
41 typedef std::vector<size_t> TConnect;
43 int GetConnect(const SMDS_ElemIteratorPtr& theNodesIter,
47 for(; theNodesIter->more();){
48 const SMDS_MeshElement* anElem = theNodesIter->next();
49 theConnect.push_back(anElem->GetID());
51 return theConnect.size();
56 Driver_Mesh::Status DriverUNV_W_SMDS_Mesh::Perform()
58 Status aResult = DRS_OK;
59 std::ofstream out_stream(myFile.c_str());
62 using namespace UNV2411;
63 TDataSet aDataSet2411;
64 // Storing SMDS nodes to the UNV file
65 //-----------------------------------
66 MESSAGE("Perform - myMesh->NbNodes() = "<<myMesh->NbNodes());
67 SMDS_NodeIteratorPtr aNodesIter = myMesh->nodesIterator();
68 for(; aNodesIter->more();){
69 const SMDS_MeshNode* aNode = aNodesIter->next();
71 aRec.coord[0] = aNode->X();
72 aRec.coord[1] = aNode->Y();
73 aRec.coord[2] = aNode->Z();
74 const TNodeLab& aLabel = aNode->GetID();
75 aDataSet2411.insert(TDataSet::value_type(aLabel,aRec));
77 MESSAGE("Perform - aDataSet2411.size() = "<<aDataSet2411.size());
78 UNV2411::Write(out_stream,aDataSet2411);
81 using namespace UNV2412;
82 TDataSet aDataSet2412;
86 MESSAGE("Perform - myMesh->NbEdges() = "<<myMesh->NbEdges());
87 if(myMesh->NbEdges()){
88 SMDS_EdgeIteratorPtr anIter = myMesh->edgesIterator();
89 for(; anIter->more();){
90 const SMDS_MeshEdge* anElem = anIter->next();
91 TElementLab aLabel = anElem->GetID();
92 int aNbNodes = anElem->NbNodes();
94 aRec.node_labels.reserve(aNbNodes);
95 SMDS_ElemIteratorPtr aNodesIter;
96 if( anElem->IsQuadratic() ) {
97 aNodesIter = static_cast<const SMDS_QuadraticEdge* >
98 ( anElem )->interlacedNodesElemIterator();
99 aRec.fe_descriptor_id = 22;
101 aNodesIter = anElem->nodesIterator();
102 aRec.fe_descriptor_id = 11;
104 for(; aNodesIter->more();){
105 const SMDS_MeshElement* aNode = aNodesIter->next();
106 aRec.node_labels.push_back(aNode->GetID());
108 aDataSet2412.insert(TDataSet::value_type(aLabel,aRec));
110 MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
113 MESSAGE("Perform - myMesh->NbFaces() = "<<myMesh->NbFaces());
114 if(myMesh->NbFaces()){
115 SMDS_FaceIteratorPtr anIter = myMesh->facesIterator();
116 for(; anIter->more();){
117 const SMDS_MeshFace* anElem = anIter->next();
118 TElementLab aLabel = anElem->GetID();
119 int aNbNodes = anElem->NbNodes();
121 aRec.node_labels.reserve(aNbNodes);
122 SMDS_ElemIteratorPtr aNodesIter;
123 if( anElem->IsQuadratic() )
124 aNodesIter = static_cast<const SMDS_QuadraticFaceOfNodes* >
125 ( anElem )->interlacedNodesElemIterator();
127 aNodesIter = anElem->nodesIterator();
128 for(; aNodesIter->more();){
129 const SMDS_MeshElement* aNode = aNodesIter->next();
130 aRec.node_labels.push_back(aNode->GetID());
134 aRec.fe_descriptor_id = 41;
137 aRec.fe_descriptor_id = 44;
140 aRec.fe_descriptor_id = 42;
143 aRec.fe_descriptor_id = 45;
148 aDataSet2412.insert(TDataSet::value_type(aLabel,aRec));
150 MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
153 MESSAGE("Perform - myMesh->NbVolumes() = "<<myMesh->NbVolumes());
154 if(myMesh->NbVolumes()){
155 SMDS_VolumeIteratorPtr anIter = myMesh->volumesIterator();
156 for(; anIter->more();){
157 const SMDS_MeshVolume* anElem = anIter->next();
158 TElementLab aLabel = anElem->GetID();
160 int aNbNodes = anElem->NbNodes();
161 aConnect.resize(aNbNodes);
163 SMDS_ElemIteratorPtr aNodesIter = anElem->nodesIterator();
164 GetConnect(aNodesIter,aConnect);
170 static int anIds[] = {0,2,1,3};
176 static int anIds[] = {0,2,1,3,5,4};
182 static int anIds[] = {0,3,2,1,4,7,6,5};
188 static int anIds[] = {0,4,2,9,5,3, 1,6,8, 7};
194 static int anIds[] = {0,6,4,2,7,5,3,1,8,11,10,9,12};
200 static int anIds[] = {0,4,2,9,13,11,5,3,1,14,12,10,6,8,7};
206 static int anIds[] = {0,6, 4,2, 12,18,16,14,7, 5, 3, 1, 19,17,15,13,8, 11,10,9};
216 aRec.fe_descriptor_id = anId;
217 aRec.node_labels.resize(aNbNodes);
218 for(int aNodeId = 0; aNodeId < aNbNodes; aNodeId++){
219 aRec.node_labels[aConn[aNodeId]] = aConnect[aNodeId];
221 aDataSet2412.insert(TDataSet::value_type(aLabel,aRec));
224 MESSAGE("Perform - aDataSet2412.size() = "<<aDataSet2412.size());
226 UNV2412::Write(out_stream,aDataSet2412);
229 using namespace UNV2417;
230 if (myGroups.size() > 0) {
231 TDataSet aDataSet2417;
232 TGroupList::const_iterator aIter = myGroups.begin();
233 for (; aIter != myGroups.end(); aIter++) {
234 SMESHDS_GroupBase* aGroupDS = *aIter;
236 aRec.GroupName = aGroupDS->GetStoreName();
239 SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
240 if (aGroupDS->GetType() == SMDSAbs_Node) {
241 aRec.NodeList.resize(aGroupDS->Extent());
243 while (aIter->more()) {
244 const SMDS_MeshElement* aElem = aIter->next();
245 aRec.NodeList[i] = aElem->GetID();
249 aRec.ElementList.resize(aGroupDS->Extent());
251 while (aIter->more()) {
252 const SMDS_MeshElement* aElem = aIter->next();
253 aRec.ElementList[i] = aElem->GetID();
257 aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
259 UNV2417::Write(out_stream,aDataSet2417);
264 using namespace UNV2417;
265 TDataSet aDataSet2417;
266 for ( TGroupsMap::iterator it = myGroupsMap.begin(); it != myGroupsMap.end(); it++ ) {
267 SMESH_Group* aGroup = it->second;
268 SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
271 aRec.GroupName = aGroup->GetName();
273 SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
274 if (aGroupDS->GetType() == SMDSAbs_Node) {
275 aRec.NodeList.resize(aGroupDS->Extent());
277 while (aIter->more()) {
278 const SMDS_MeshElement* aElem = aIter->next();
279 aRec.NodeList[i] = aElem->GetID();
283 aRec.ElementList.resize(aGroupDS->Extent());
285 while (aIter->more()) {
286 const SMDS_MeshElement* aElem = aIter->next();
287 aRec.ElementList[i] = aElem->GetID();
291 aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
294 UNV2417::Write(out_stream,aDataSet2417);
299 if (!check_file(myFile))
300 EXCEPTION(runtime_error,"ERROR: Output file not good.");
302 catch(const std::exception& exc){
303 INFOS("Follow exception was cought:\n\t"<<exc.what());
307 INFOS("Unknown exception was cought !!!");