Salome HOME
9dcabfed4041c18e797688fb4f2a0e0f5549a30f
[modules/hexablock.git] / src / HEXABLOCK / HexVertex.hxx
1
2 // Class : Gestion des sommets
3
4 // Copyright (C) 2009-2013  CEA/DEN, EDF R&D
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #ifndef __VERTEX_H_
24 #define __VERTEX_H_
25
26 #include "HexEltBase.hxx"
27
28 BEGIN_NAMESPACE_HEXA
29
30 class Vertex : public EltBase
31 {
32 public :
33    double getX()   { return v_x; }
34    double getY()   { return v_y; }
35    double getZ()   { return v_z; }
36    double getCoord (int dir);
37
38    virtual int     countVertex ()       { return 1; }
39    virtual Vertex* getVertex (int nro)  { return this; }
40
41
42    void setX (double v)   { v_x = v ; }
43    void setY (double v)   { v_y = v ; }
44    void setZ (double v)   { v_z = v ; }
45
46    virtual void setAssociation (Shape* forme)  {}     // PERIME
47                                                    // Hexa5
48    int  setAssociation (NewShape* geom, int subid);
49    int  setAssociation (VertexShape* forme);
50    int  setAssociation (double* point);
51    int  setAssociation (double px, double py, double pz);
52    void clearAssociation ();
53
54    VertexShape* getAssoVertex ()              { return v_shape ;}
55    VertexShape* getAssociation ()             { return v_shape ;}
56
57    void   getAssoCoord (double &x, double &y, double &z);
58    void   getAssoCoord (double* point);
59
60    double getAssoX ()   { return is_associated ? gc_x : v_x ; }
61    double getAssoY ()   { return is_associated ? gc_y : v_y ; }
62    double getAssoZ ()   { return is_associated ? gc_z : v_z ; }
63
64 public :
65    Vertex (Document* prev, double x=0.0, double y=0.0, double z=0.0);
66    Vertex (Vertex* other);
67    virtual ~Vertex () {}
68    virtual void dump () ;
69    virtual void saveXml (XmlWriter* xml);
70
71    void    setScalar (double val)             { v_scalar = val ; }
72    double  getScalar ()                       { return v_scalar ; }
73    void    setColor  (double valeur)          { setScalar (valeur) ; }
74    double* getPoint (double point[]);
75
76    void setCoord  (double x, double y, double z);
77    void setCoord  (double point[]) { setCoord (point[0], point[1], point[2]); }
78
79    bool isin      (double xmin, double xmax, double ymin, double ymax,
80                                             double zmin, double zmax);
81    Edge* getParent (int nro);
82    Vertex* makeSymetric (Vertex* other);
83    void    translate (Vector* vecteur, double fact=1.0);
84    void    replace   (Vertex* old);
85
86    Vertex* getClone ()              {  return v_clone ; }
87    void    duplicate (Document* doc);
88
89    static Vertex* createMiddle (Vertex* left, Vertex* right);
90    bool   definedBy (double px, double py, double pz, double eps2=1e-4);
91
92 private :
93     double v_x;
94     double v_y;
95     double v_z;
96
97     double  v_scalar;
98     Vertex* v_clone;
99     double  gc_x, gc_y, gc_z;
100     VertexShape*  v_shape;
101 };
102 // ========================================================= Constructeur bis
103 inline Vertex::Vertex (Vertex* other)
104       : EltBase (other->dad(), EL_VERTEX)
105 {
106    if (other!= NULL)
107       {
108       v_x = other->v_x;
109       v_y = other->v_y;
110       v_z = other->v_z;
111       v_scalar = other->v_scalar;
112       gc_x   = other->gc_x;
113       gc_y   = other->gc_y;
114       gc_z   = other->gc_z;
115       v_clone  = NULL;
116       v_shape  = other->v_shape;
117       }
118    else
119       {
120       v_x  = v_y  = v_z  = 0;
121       gc_x = gc_y = gc_z = 0;
122       v_scalar = 0;
123       v_shape  = NULL;
124       v_clone  = NULL;
125       }
126 }
127 // ===================================================== getCoord
128 inline double Vertex::getCoord (int dir)
129 {
130    double val = 0;
131    switch (dir)
132           {
133           case dir_x : val = v_x;
134                break;
135           case dir_y : val = v_y;
136                break;
137           case dir_z : val = v_z;
138                break;
139           }
140    return val;
141 }
142 // ========================================================= dump
143 inline void Vertex::dump ()
144 {
145    printName (" = ");
146    if (NOT isHere ())
147       {
148       printf ("(*** deleted ***)\n");
149       return;
150       }
151
152    printf ("(%g, %g, %g)", v_x,v_y,v_z);
153    dumpRef ();
154 }
155 // ========================================================= setCoord
156 inline void Vertex::setCoord (double x, double y, double z)
157 {
158    v_x = x;
159    v_y = y;
160    v_z = z;
161 }
162 // ========================================================= isin
163 inline bool Vertex::isin  (double xmin, double xmax, double ymin, double ymax,
164                                              double zmin, double zmax)
165 {
166    bool   rep =   v_x >= xmin && v_x <= xmax
167                && v_y >= ymin && v_y <= ymax
168                && v_z >= zmin && v_z <= zmax;
169    return rep;
170 }
171 // ========================================================= getPoint
172 inline double* Vertex::getPoint (double point[])
173 {
174    point [dir_x] = v_x;
175    point [dir_y] = v_y;
176    point [dir_z] = v_z;
177    return point;
178 }
179 // ========================================================= duplicate
180 inline void Vertex::duplicate (Document* cible)
181 {
182    v_clone = new Vertex (cible, v_x, v_y, v_z);
183    v_clone->v_scalar = v_scalar;
184 }
185 // ========================================================= duplicate
186 inline bool Vertex::definedBy (double px, double py, double pz, double eps2)
187 {
188    double dist2 = carre (v_x-px) + carre (v_y-py) + carre (v_z-pz);
189    return dist2 < eps2;
190 }
191 END_NAMESPACE_HEXA
192 #endif