Salome HOME
Merge branch V7_3_1_BR
[modules/hexablock.git] / src / HEXABLOCK / HexAssoEdge.cxx
1 //
2 // C++ : Implementation des associations d'edges
3 //
4 // Copyright (C) 2009-2014  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, or (at your option) any later version.
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 #include "HexAssoEdge.hxx"
24 #include "HexXmlWriter.hxx"
25
26 #include <BRep_Builder.hxx>
27 #include <BRepAdaptor_Curve.hxx>
28
29 #include <GCPnts_AbscissaPoint.hxx>
30
31 BEGIN_NAMESPACE_HEXA
32
33 // static bool db = on_debug ();
34
35 // ======================================================= Constructeur
36 AssoEdge::AssoEdge (EdgeShape* shape, double deb, double fin)
37 {
38    arc_line  = shape;
39    arc_para1 = std::min (deb, fin);
40    arc_para2 = std::max (deb, fin);
41
42    arc_line->getPoint (arc_para1, arc_start);
43    arc_line->getPoint (arc_para2, arc_end);
44
45    //  arc_curve   = arc_line->getCurve (); Provisoire en attendant modif plugin
46    arc_curve   = arc_line->makeCurve ();
47    arc_reverse = false;
48 }
49 // ========================================================= onExtremity
50 int AssoEdge::onExtremity (double* point)
51 {
52    if (EdgeShape::samePoints  (point, arc_start))
53       return V_AMONT;
54    else if (EdgeShape::samePoints  (point, arc_end))
55       return V_AVAL;
56    else
57       return NOTHING;
58 }
59 // ========================================================= onExtremity
60 int AssoEdge::onExtremity (AssoEdge* other, int& ext_other)
61 {
62    ext_other = NOTHING;
63    if (other==NULL)
64       return NOTHING;
65
66    int rep = onExtremity (other->arc_start);
67    if (rep != NOTHING)
68       {
69       ext_other = V_AMONT;
70       }
71    else
72       {
73       rep = onExtremity (other->arc_end);
74       if (rep != NOTHING)
75           ext_other = V_AVAL;
76       }
77
78    return rep;
79 }
80 // ========================================================= length
81 double AssoEdge::length ()
82 {
83    double longueur = (arc_para2-arc_para1)*arc_line->getLength ();
84    return longueur;
85 }
86 // ========================================================= getUstart
87 double AssoEdge::getUstart ()
88 {
89    double ustart = 0;
90    BRepAdaptor_Curve* curve = arc_line->getCurve () ;
91    double             len   = arc_line->getLength ();
92
93    GCPnts_AbscissaPoint discret_start (*curve, len*arc_para1,
94                                         curve->FirstParameter() );
95    ustart = discret_start.Parameter();
96    return ustart;
97 }
98 // ========================================================= saveXml
99 void AssoEdge::saveXml (XmlWriter* xml)
100 {
101    char     interval [80];
102    sprintf (interval, "%g %g", arc_para1, arc_para2);
103
104    arc_line->callXml (xml);
105    xml->addAttribute ("interval", interval);
106    xml->closeMark ();
107 }
108 // ========================================================= setStart
109 void AssoEdge::setStart (double param)
110 {
111    arc_para1 = param;
112    arc_line->getPoint (arc_para1, arc_start);
113 }
114 // ========================================================= setEnd
115 void AssoEdge::setEnd (double param)
116 {
117    arc_para2 = param;
118    arc_line->getPoint (arc_para2, arc_end);
119 }
120 // -----------------------------------------------------------------------
121 // ========================================================= dump
122 void AssoEdge::dump ()
123 {
124    cout << " AssoEddge = " << arc_line->getName()
125         << " (" << arc_para1 << ", " << arc_para2 << ")" << endl;
126
127    PutCoord (arc_start);
128    PutCoord (arc_end);
129 }
130 END_NAMESPACE_HEXA