Salome HOME
Export UNV groups
authorvsv <vsv@opencascade.com>
Tue, 4 Apr 2006 10:19:22 +0000 (10:19 +0000)
committervsv <vsv@opencascade.com>
Tue, 4 Apr 2006 10:19:22 +0000 (10:19 +0000)
src/DriverUNV/DriverUNV_W_SMDS_Mesh.cxx
src/DriverUNV/DriverUNV_W_SMDS_Mesh.h
src/DriverUNV/UNV2417_Structure.cxx
src/DriverUNV/UNV2417_Structure.hxx
src/DriverUNV/UNV_Test.cxx
src/SMESH/SMESH_Mesh.cxx

index 945192a56a40e1e4852d86309dc56b414c66aa46..4e75a762fc8e559a51244dcd10c4e605cbeb318a 100644 (file)
@@ -22,6 +22,8 @@
 #include "DriverUNV_W_SMDS_Mesh.h"
 
 #include "SMDS_Mesh.hxx"
+#include "SMESHDS_GroupBase.hxx"
+#include "SMESH_Group.hxx"
 #include "SMDS_QuadraticEdge.hxx"
 #include "SMDS_QuadraticFaceOfNodes.hxx"
 
@@ -29,6 +31,7 @@
 
 #include "UNV2411_Structure.hxx"
 #include "UNV2412_Structure.hxx"
+#include "UNV2417_Structure.hxx"
 #include "UNV_Utilities.hxx"
 
 using namespace std;
@@ -221,6 +224,39 @@ Driver_Mesh::Status DriverUNV_W_SMDS_Mesh::Perform()
       }
       UNV2412::Write(out_stream,aDataSet2412);
     }
+    {
+      using namespace UNV2417;
+      TDataSet aDataSet2417;
+      for ( TGroupsMap::iterator it = myGroupsMap.begin(); it != myGroupsMap.end(); it++ ) {
+       SMESH_Group*       aGroup   = it->second;
+       SMESHDS_GroupBase* aGroupDS = aGroup->GetGroupDS();
+       if ( aGroupDS ) {
+         TRecord aRec;
+         aRec.GroupName = aGroup->GetName();
+         int i;
+         SMDS_ElemIteratorPtr aIter = aGroupDS->GetElements();
+         if (aGroupDS->GetType() == SMDSAbs_Node) {
+           aRec.NodeList.resize(aGroupDS->Extent());
+           i = 0;
+           while (aIter->more()) {
+             const SMDS_MeshElement* aElem = aIter->next();
+             aRec.NodeList[i] = aElem->GetID(); 
+             i++;
+           }
+         } else {
+           aRec.ElementList.resize(aGroupDS->Extent());
+           i = 0;
+           while (aIter->more()) {
+             const SMDS_MeshElement* aElem = aIter->next();
+             aRec.ElementList[i] = aElem->GetID(); 
+             i++;
+           }
+         }
+         aDataSet2417.insert(TDataSet::value_type(aGroupDS->GetID(), aRec));
+       }
+      }
+      UNV2417::Write(out_stream,aDataSet2417);
+    }
   }
   catch(const std::exception& exc){
     INFOS("Follow exception was cought:\n\t"<<exc.what());
index 88ff5e83cccc376e04ca915cf54c3d0e40430c39..aed5c1ba38c30c7558488a2c9d15bc9f86a77246 100644 (file)
 #define _INCLUDE_DRIVERUNV_W_SMDS_MESH
 
 #include "Driver_SMDS_Mesh.h"
+#include "SMESH_Group.hxx"
+#include <map>
+
+
+typedef std::map<int, SMESH_Group*> TGroupsMap;
 
 class DriverUNV_W_SMDS_Mesh: public Driver_SMDS_Mesh
 {
  public:
   virtual Status Perform();
+
+  void SetGroups(const TGroupsMap& theGroupsMap) { myGroupsMap = theGroupsMap; }
+
+ private:
+  TGroupsMap myGroupsMap;
 };
 
 
index f5e84926c78144f83f4757f18c955386e1865416..4d3eac88eaaee646379efa10d72aaf5a15330940 100644 (file)
@@ -1,6 +1,9 @@
 #include "UNV2417_Structure.hxx"
 #include "UNV_Utilities.hxx"
 
+#include <fstream>     
+#include <iomanip>
+
 using namespace std;
 using namespace UNV;
 using namespace UNV2417;
@@ -12,10 +15,10 @@ static int MYDEBUG = 0;
 #endif
 
 
-static string _group_labels[] = {"2417", "2429", "2430", "2432", "2435"};
-#define NBGROUP 5
+static string _group_labels[] = {"2417", "2429", "2430", "2432", "2435", "2452"};
+#define NBGROUP 6
 
-//static string _label_dataset = "2435";
+static string _label_dataset = "2429";
 
 void UNV2417::Read(std::ifstream& in_stream, TDataSet& theDataSet)
 {
@@ -72,10 +75,10 @@ void UNV2417::ReadGroup(const std::string& myGroupLabel, std::ifstream& in_strea
     int aElType;
     int aElId;
     int aNum;
-        for(int j=0; j < n_nodes; j++){
+    for(int j=0; j < n_nodes; j++){
       in_stream>>aElType;
       in_stream>>aElId;
-      if (myGroupLabel.compare("2435") == 0) {
+      if ((myGroupLabel.compare("2435") == 0) || (myGroupLabel.compare("2452") == 0)) {
        in_stream>>aTmp;
        in_stream>>aTmp;
       }
@@ -96,3 +99,62 @@ void UNV2417::ReadGroup(const std::string& myGroupLabel, std::ifstream& in_strea
   }
 
 }
+
+
+void UNV2417::Write(std::ofstream& out_stream, const TDataSet& theDataSet)
+{
+  if(!out_stream.good())
+    EXCEPTION(runtime_error,"ERROR: Output file not good.");
+  
+  /*
+   * Write beginning of dataset
+   */
+  out_stream<<"    -1\n";
+  out_stream<<"  "<<_label_dataset<<"\n";
+
+  TDataSet::const_iterator anIter = theDataSet.begin();
+  for(; anIter != theDataSet.end(); anIter++){
+    const TGroupId& aLabel = anIter->first;
+    const TRecord& aRec = anIter->second;
+    int aNbNodes = aRec.NodeList.size();
+    int aNbElements = aRec.ElementList.size();
+    int aNbRecords = aNbNodes + aNbElements;
+
+    out_stream<<std::setw(10)<<aLabel;  /* group ID */
+    out_stream<<std::setw(10)<<0;  
+    out_stream<<std::setw(10)<<0;
+    out_stream<<std::setw(10)<<0;
+    out_stream<<std::setw(10)<<0;
+    out_stream<<std::setw(10)<<0;
+    out_stream<<std::setw(10)<<0;
+    out_stream<<std::setw(10)<<aNbRecords<<std::endl; 
+
+    out_stream<<aRec.GroupName<<std::endl;
+    int aRow = 0;
+    int i;
+    for (i = 0; i < aNbNodes; i++) {
+      if (aRow == 4) {
+       out_stream<<std::endl; 
+       aRow = 0;
+      }
+      out_stream<<std::setw(10)<<7;
+      out_stream<<std::setw(10)<<aRec.NodeList[i];
+      aRow++;
+    }
+    for (i = 0; i < aNbElements; i++) {
+      if (aRow == 4) {
+       out_stream<<std::endl; 
+       aRow = 0;
+      }
+      out_stream<<std::setw(10)<<8;
+      out_stream<<std::setw(10)<<aRec.ElementList[i];
+      aRow++;
+    }
+    out_stream<<std::endl; 
+  }
+
+  /*
+   * Write end of dataset
+   */
+  out_stream<<"    -1\n";
+}
index b502c7b786a8abcddee391de028dca914b525bf1..d5dc3124956928722f035a1aeaf206875a259c07 100644 (file)
@@ -41,6 +41,8 @@ namespace UNV2417{
 
   void Read(std::ifstream& in_stream, TDataSet& theDataSet);
   void ReadGroup(const std::string& myGroupLabel, std::ifstream& in_stream, TDataSet& theDataSet);
+
+  void Write(std::ofstream& out_stream, const TDataSet& theDataSet);
 };
 
 
index 0156b5051a489fc060f57698057ffb777eb4c041..1eb39c4520840747f81260cc4ec7faf8698d4c40 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "DriverUNV_R_SMDS_Mesh.h"
 #include "DriverUNV_W_SMDS_Mesh.h"
+#include "SMESH_Group.hxx"
 
 using namespace std;
 
index 62e3575fda118b69aab22d48493eef3cec405d0c..634cf721ca365735ae2dfd429ed73dc28c26b210 100644 (file)
@@ -948,6 +948,7 @@ void SMESH_Mesh::ExportUNV(const char *file) throw(SALOME_Exception)
   myWriter.SetFile(string(file));
   myWriter.SetMesh(_myMeshDS);
   myWriter.SetMeshId(_idDoc);
+  myWriter.SetGroups(_mapGroup);
   myWriter.Perform();
 }