Salome HOME
Merge branch 'V7_dev'
[plugins/blsurfplugin.git] / src / BLSURFPlugin / BLSURFPlugin_BLSURF.hxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // ---
21 // File    : BLSURFPlugin_BLSURF.hxx
22 // Authors : Francis KLOSS (OCC) & Patrick LAUG (INRIA) & Lioka RAZAFINDRAZAKA (CEA)
23 //           & Aurelien ALLEAUME (DISTENE)
24 //           Size maps developement: Nicolas GEIMER (OCC) & Gilles DAVID (EURIWARE)
25 // ---
26 //
27 #ifndef _BLSURFPlugin_BLSURF_HXX_
28 #define _BLSURFPlugin_BLSURF_HXX_
29
30 #include <TopoDS.hxx>
31 #include <TopoDS_Vertex.hxx>
32 #include <TopoDS_Edge.hxx>
33 #include <TopoDS_Wire.hxx>
34 #include <TopoDS_Face.hxx>
35 #include <TopoDS_Shape.hxx>
36
37 #ifdef HAVE_FINITE
38 #undef HAVE_FINITE            // VSR: avoid compilation warning on Linux : "HAVE_FINITE" redefined
39 #endif
40 // rnv: avoid compilation warning on Linux : "_POSIX_C_SOURCE" and "_XOPEN_SOURCE" are redefined
41 #ifdef _POSIX_C_SOURCE
42 #undef _POSIX_C_SOURCE
43 #endif
44
45 #ifdef _XOPEN_SOURCE
46 #undef _XOPEN_SOURCE
47 #endif
48
49 #include <Python.h>
50 #include <SMESH_Algo.hxx>
51 #include <SMESH_Mesh.hxx>
52 #include <SMESHDS_Mesh.hxx>
53 #include <SMDS_MeshElement.hxx>
54 #include <SMDS_MeshNode.hxx>
55 #include <SMESH_Gen_i.hxx>
56 #include <StdMeshers_ViscousLayers2D.hxx>
57 #include <SALOMEconfig.h>
58 #include CORBA_CLIENT_HEADER(SALOMEDS)
59 #include CORBA_CLIENT_HEADER(GEOM_Gen)
60 #include "Utils_SALOME_Exception.hxx"
61
62 extern "C"{
63 #include <meshgems/meshgems.h>
64 #include <meshgems/cadsurf.h>
65 #include <meshgems/precad.h>
66 }
67
68 #include <BRepClass_FaceClassifier.hxx>
69 #include <BRepAdaptor_Surface.hxx>
70 #include <BRepTools.hxx>
71 #include <BRepAdaptor_HSurface.hxx>
72
73 #include "BLSURFPlugin_Hypothesis.hxx"
74
75 class TopoDS_Shape;
76
77 class BLSURFPlugin_BLSURF: public SMESH_2D_Algo {
78   public:
79     BLSURFPlugin_BLSURF(int hypId, int studyId, SMESH_Gen* gen);
80
81     virtual ~BLSURFPlugin_BLSURF();
82
83     virtual bool CheckHypothesis(SMESH_Mesh&                          aMesh,
84                                  const TopoDS_Shape&                  aShape,
85                                  SMESH_Hypothesis::Hypothesis_Status& aStatus);
86
87     void SetParameters(const BLSURFPlugin_Hypothesis* hyp, blsurf_session_t *bls, precad_session_t *pcs, const TopoDS_Shape& shape, bool *use_precad);
88
89     virtual bool Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape);
90
91     virtual void CancelCompute();
92     bool computeCanceled() { return _compute_canceled; }
93
94     virtual bool Evaluate(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape,
95                           MapShapeNbElems& aResMap);
96
97     // List of ids
98     typedef std::vector<int> TListOfIDs;
99
100     // PreCad Edges periodicity
101     struct TPreCadPeriodicityIDs {
102       TListOfIDs shape1IDs;
103       TListOfIDs shape2IDs;
104       std::vector<double> theSourceVerticesCoords;
105       std::vector<double> theTargetVerticesCoords;
106     };
107
108     // Edge periodicity
109     struct TEdgePeriodicityIDs {
110       int theFace1ID;
111       int theEdge1ID;
112       int theFace2ID;
113       int theEdge2ID;
114       int edge_orientation;
115     };
116
117     // Vertex periodicity
118     struct TVertexPeriodicityIDs {
119       int theEdge1ID;
120       int theVertex1ID;
121       int theEdge2ID;
122       int theVertex2ID;
123     };
124
125     // Vector of pairs of ids
126     typedef std::vector< TPreCadPeriodicityIDs > TPreCadIDsPeriodicityVector;
127     typedef std::vector< std::pair<int, int> > TShapesIDsPeriodicityVector;
128     typedef std::vector< TEdgePeriodicityIDs > TEdgesIDsPeriodicityVector;
129     typedef std::vector< TVertexPeriodicityIDs > TVerticesIDsPeriodicityVector;
130
131
132
133   protected:
134     const BLSURFPlugin_Hypothesis* _hypothesis;
135     bool                           _haveViscousLayers;
136
137     TPreCadIDsPeriodicityVector _preCadFacesIDsPeriodicityVector;
138     TPreCadIDsPeriodicityVector _preCadEdgesIDsPeriodicityVector;
139
140     TShapesIDsPeriodicityVector _facesIDsPeriodicityVector;
141     TEdgesIDsPeriodicityVector _edgesIDsPeriodicityVector;
142     TVerticesIDsPeriodicityVector _verticesIDsPeriodicityVector;
143
144   private:
145     bool compute(SMESH_Mesh&          aMesh,
146                  const TopoDS_Shape&  aShape,
147                  bool                 allowSubMeshClearing);
148
149     void set_param(cadsurf_session_t *css,
150                    const char *       option_name,
151                    const char *       option_value);
152
153     TopoDS_Shape entryToShape(std::string entry);
154     void addCoordsFromVertices(const std::vector<std::string> &theVerticesEntries, std::vector<double> &theVerticesCoords);
155     void addCoordsFromVertex(BLSURFPlugin_Hypothesis::TEntry theVertexEntry, std::vector<double> &theVerticesCoords);
156     void createEnforcedVertexOnFace(TopoDS_Shape FaceShape, BLSURFPlugin_Hypothesis::TEnfVertexList enfVertexList);
157     void createPreCadFacesPeriodicity(TopoDS_Shape theGeomShape, const BLSURFPlugin_Hypothesis::TPreCadPeriodicity &preCadPeriodicity);
158     void createPreCadEdgesPeriodicity(TopoDS_Shape theGeomShape, const BLSURFPlugin_Hypothesis::TPreCadPeriodicity &preCadPeriodicity);
159     void createFacesPeriodicity(TopoDS_Shape theGeomShape, BLSURFPlugin_Hypothesis::TEntry theFace1,  BLSURFPlugin_Hypothesis::TEntry theFace2);
160     void createEdgesPeriodicity(TopoDS_Shape theGeomShape, BLSURFPlugin_Hypothesis::TEntry theFace1, BLSURFPlugin_Hypothesis::TEntry theEdge1,
161         BLSURFPlugin_Hypothesis::TEntry theFace2, BLSURFPlugin_Hypothesis::TEntry theEdge2, int edge_orientation = 0);
162     void createVerticesPeriodicity(TopoDS_Shape theGeomShape, BLSURFPlugin_Hypothesis::TEntry theEdge1, BLSURFPlugin_Hypothesis::TEntry theVertex1,
163         BLSURFPlugin_Hypothesis::TEntry theEdge2, BLSURFPlugin_Hypothesis::TEntry theVertex2);
164     void Set_NodeOnEdge(SMESHDS_Mesh* meshDS, const SMDS_MeshNode* node, const TopoDS_Shape& ed);
165     void BRepClass_FaceClassifierPerform(BRepClass_FaceClassifier* fc, const TopoDS_Face& face, const gp_Pnt& P, const Standard_Real Tol);
166
167   private:
168       PyObject *          main_mod;
169       PyObject *          main_dict;
170       SMESH_Mesh*         myMesh;
171       SALOMEDS::Study_var myStudy;
172       SMESH_Gen_i*        smeshGen_i;
173
174       volatile bool _compute_canceled;
175 };
176
177 #endif