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