Salome HOME
Merge remote-tracking branch 'origin/master' into V9_dev
[modules/hexablock.git] / src / HEXABLOCK / HexNewShape.cxx
index 79ac508719eff565a7abae318c730b9008ac7f2a..7de14881d2cf56d074906498565a10aa3126b9dc 100755 (executable)
@@ -1,12 +1,12 @@
 
 // C++ : Gestion des Shapes (Hexa v5)
 
-// Copyright (C) 2009-2013  CEA/DEN, EDF R&D
+// Copyright (C) 2009-2016  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 #include "HexQuad.hxx"
 #include "HexEdge.hxx"
+#include "HexMatrix.hxx"
 
 #include "HexKas_functions.hxx"
 
 #include "HexXmlWriter.hxx"
 #include "HexXmlTree.hxx"
 
-#ifndef NO_CASCADE
 #include <TopoDS.hxx>
 #include <TopoDS_Iterator.hxx>
 #include <TopoDS_Edge.hxx>
@@ -44,6 +44,7 @@
 #include <BRep_Builder.hxx>
 #include <BRepBuilderAPI_MakeEdge.hxx>
 #include <BRepPrimAPI_MakeSphere.hxx>
+#include <BRepBuilderAPI_Transform.hxx>
 
 #include <BRep_Tool.hxx>
 
 #include <gp_Lin.hxx>
 #include <gp_Circ.hxx>
 
-
 BEGIN_NAMESPACE_HEXA
 
 static bool db  = on_debug ();  // == getenv ("HEXA_DB") > 0
-static bool db0 = true;
+static bool db0 = db;
 
 // ====================================================== Constructeur
 NewShape::NewShape (Document* dad, EnumShape type)
@@ -171,6 +171,41 @@ int NewShape::addSphere (double* milieu, double radius)
    curr_subid += 7;
    return subid;
 }
+// ====================================================== transfoShape
+int NewShape::transfoShape (Matrix& matrice, SubShape* shape)
+{
+   gp_Trsf transfo;
+   double             a11,a12,a13,a14, a21,a22,a23,a24, a31,a32,a33,a34;
+   matrice.getCoeff  (a11,a12,a13,a14, a21,a22,a23,a24, a31,a32,a33,a34);
+   transfo.SetValues (a11,a12,a13,a14, a21,a22,a23,a24, a31,a32,a33,a34);
+
+   TopoDS_Shape shape_orig = shape->getShape ();
+   BRepBuilderAPI_Transform builder (shape_orig, transfo, Standard_True);
+   TopoDS_Shape result = builder.Shape();
+
+   geo_builder.Add (geo_compound, result);
+
+   int  subid  = curr_subid;
+   curr_subid += 2;                       // PROVISOIRE
+   return subid;
+}
+// ====================================================== translateShape
+int NewShape::translateShape (double dir[], SubShape* shape)
+{
+   gp_Trsf transfo;
+   gp_Vec  vecteur        (dir [dir_x], dir [dir_y], dir [dir_z]);
+   transfo.SetTranslation (vecteur);
+
+   TopoDS_Shape shape_orig = shape->getShape ();
+   BRepBuilderAPI_Transform builder (shape_orig, transfo, Standard_True);
+   TopoDS_Shape result = builder.Shape();
+
+   geo_builder.Add (geo_compound, result);
+
+   int  subid  = curr_subid;
+   curr_subid += 2;                       // PROVISOIRE
+   return subid;
+}
 // ====================================================== addAssociation
 void NewShape::addAssociation (Vertex* vertex, int subid, double param)
 {
@@ -187,6 +222,15 @@ void NewShape::addAssociation (Edge* edge, int subid, double pmin, double pmax)
    if (edge==NULL)
       return;
 
+   if (db0) 
+      {
+      cout << edge->getName() 
+           << " = (" << edge->getVertex(0)->getName() 
+           << ", "   << edge->getVertex(1)->getName() 
+           << ") --> subid= " << subid << " [ " 
+           << pmin << ", " << pmax << "]" << endl;
+      }
+
    asso_edge.push_back (edge);
    asso_pmin.push_back (pmin);
    asso_pmax.push_back (pmax);
@@ -245,6 +289,18 @@ VertexShape* NewShape::findVertex (int shid)
        }
    return NULL;
 }
+// ====================================================== findVertex
+VertexShape* NewShape::findVertex (double point[])
+{
+   int nbre = tab_vertex.size ();
+   for (int nro=0 ; nro < nbre ; nro++)
+       {
+       VertexShape* shape = tab_vertex [nro];
+       if (shape->definedBy (point))
+          return shape;
+       }
+   return NULL;
+}
 // ====================================================== findEdge
 EdgeShape* NewShape::findEdge (int shid)
 {
@@ -257,6 +313,18 @@ EdgeShape* NewShape::findEdge (int shid)
        }
    return NULL;
 }
+// ====================================================== findEdge
+EdgeShape* NewShape::findEdge (double p1[], double p2[])
+{
+   int nbre = tab_edge.size ();
+   for (int nro=0 ; nro < nbre ; nro++)
+       {
+       EdgeShape* shape = tab_edge [nro];
+       if (shape->definedBy (p1, p2))
+          return shape;
+       }
+   return NULL;
+}
 // ====================================================== findFace
 FaceShape* NewShape::findFace (int shid)
 {
@@ -283,7 +351,7 @@ SubShape* NewShape::findSubShape (int shid)
 // ====================================================== getVertex
 int NewShape::getVertex (int nro)
 {
-   if (nro <0 || nro >= tab_vertex.size())
+   if (nro <0 || nro >= (int) tab_vertex.size())
       return 0;
 
    SubShape* shape = tab_vertex [nro];
@@ -292,7 +360,7 @@ int NewShape::getVertex (int nro)
 // ====================================================== getEdge
 int NewShape::getEdge   (int nro)
 {
-   if (nro <0 || nro >= tab_edge.size())
+   if (nro <0 || nro >= (int) tab_edge.size())
       return 0;
 
    SubShape* shape = tab_edge [nro];
@@ -301,7 +369,7 @@ int NewShape::getEdge   (int nro)
 // ====================================================== getFace
 int NewShape::getFace   (int nro)
 {
-   if (nro <0 || nro >= tab_face.size())
+   if (nro <0 || nro >= (int) tab_face.size())
       return 0;
 
    SubShape* shape = tab_face [nro];
@@ -311,7 +379,7 @@ int NewShape::getFace   (int nro)
 // ====================================================== getNameVertex
 cpchar NewShape::getNameVertex  (int nro)
 {
-   if (nro <0 || nro >= tab_vertex.size())
+   if (nro <0 || nro >= (int) tab_vertex.size())
       return "?";
 
    SubShape* shape = tab_vertex [nro];
@@ -320,7 +388,7 @@ cpchar NewShape::getNameVertex  (int nro)
 // ====================================================== getNameEdge
 cpchar NewShape::getNameEdge    (int nro)
 {
-   if (nro <0 || nro >= tab_edge.size())
+   if (nro <0 || nro >= (int) tab_edge.size())
       return "?";
 
    SubShape* shape = tab_edge [nro];
@@ -329,7 +397,7 @@ cpchar NewShape::getNameEdge    (int nro)
 // ====================================================== getNameFace
 cpchar NewShape::getNameFace    (int nro)
 {
-   if (nro <0 || nro >= tab_face.size())
+   if (nro <0 || nro >= (int) tab_face.size())
       return "?";
 
    SubShape* shape = tab_face [nro];
@@ -338,7 +406,7 @@ cpchar NewShape::getNameFace    (int nro)
 // ====================================================== getFaceShape
 FaceShape* NewShape::getFaceShape (int nro)
 {
-   if (nro <0 || nro >= tab_face.size())
+   if (nro <0 || nro >= (int) tab_face.size())
       return 0;
 
    FaceShape* shape = tab_face [nro];
@@ -347,7 +415,7 @@ FaceShape* NewShape::getFaceShape (int nro)
 // ====================================================== getEdgeShape
 EdgeShape* NewShape::getEdgeShape (int nro)
 {
-   if (nro <0 || nro >= tab_edge.size())
+   if (nro <0 || nro >= (int) tab_edge.size())
       return 0;
 
    EdgeShape* shape = tab_edge [nro];
@@ -356,7 +424,7 @@ EdgeShape* NewShape::getEdgeShape (int nro)
 // ====================================================== getVertexShape
 VertexShape* NewShape::getVertexShape (int nro)
 {
-   if (nro <0 || nro >= tab_vertex.size())
+   if (nro <0 || nro >= (int) tab_vertex.size())
       return 0;
 
    VertexShape* shape = tab_vertex [nro];
@@ -366,9 +434,9 @@ VertexShape* NewShape::getVertexShape (int nro)
 int NewShape::addPoint (double* point)
 {
    char suffix [32];
-   int  subid = tab_vertex.size() + 1;
+   int  subid = tab_vertex.size() + 2;
 
-   sprintf (suffix, ":vertex%02d", subid);
+   sprintf (suffix, ":vertex_%02d", subid);
    string name = el_name + suffix;
 
    VertexShape* sub_shape = new VertexShape (this, subid, point);
@@ -385,12 +453,21 @@ int NewShape::saveBrep ()
    if (ier != HOK)
       return ier;
 
-    pfile fic = fopen (filename.c_str(), "w");
-    if (fic==NULL)
-       return HERR;
+   pfile fic = fopen (filename.c_str(), "w");
+   if (fic==NULL)
+      return HERR;
 
-    fprintf (fic, "%s\n", geo_brep.c_str());
-    fclose  (fic);
+   fprintf (fic, "%s\n", geo_brep.c_str());
+   fclose  (fic);
+   return HOK;
+}
+// ===================================================== getBrep
+cpchar NewShape::getBrep ()
+{
+   int ier   = updateBrep ();
+   if (ier != HOK)
+      return NULL;
+   return geo_brep.c_str();
 }
 // ====================================================== saveXml
 void NewShape::saveXml (XmlWriter* xml)
@@ -535,26 +612,3 @@ int NewShape::updateBrep ()
    return HOK;
 }
 END_NAMESPACE_HEXA
-
-#else
-
-// ====================================================== ===================
-BEGIN_NAMESPACE_HEXA
-NewShape::NewShape (Document* dad) : EltBase  (dad, EL_SHAPE) {}
-void      NewShape::setShape (const TopoDS_Shape& shape)      {}
-void      NewShape::saveXml  (XmlWriter* xml)                 {}
-SubShape* NewShape::findSubShape (int shid)             { return NULL; }
-SubShape* NewShape::findVertex   (int shid)             { return NULL; }
-SubShape* NewShape::findEdge     (int shid)             { return NULL; }
-SubShape* NewShape::findFace     (int shid)             { return NULL; }
-
-int NewShape::getVertex (int nro)     { return 0 ; }
-int NewShape::getEdge   (int nro)     { return 0 ; }
-int NewShape::getFace   (int nro)     { return 0 ; }
-
-cpchar NewShape::getNameVertex  (int nro)     { return "Nothing" ; }
-cpchar NewShape::getNameEdge    (int nro)     { return "Nothing" ; }
-cpchar NewShape::getNameFace    (int nro)     { return "Nothing" ; }
-
-END_NAMESPACE_HEXA
-#endif