Salome HOME
6f027b97292443a4bc9dae150ca136dc0c99f67d
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IProximity.hxx
1 // Copyright (C) 2022-2023  CEA/DEN, EDF R&D, OPEN CASCADE
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 #include <GEOM_Function.hxx>
21
22 #define PROXIMITY_ARG_SHAPE1   1
23 #define PROXIMITY_ARG_SHAPE2   2
24 #define PROXIMITY_ARG_SAMPLES1 3
25 #define PROXIMITY_ARG_SAMPLES2 4
26 #define PROXIMITY_ARG_POINT1   5
27 #define PROXIMITY_ARG_POINT2   6
28 #define PROXIMITY_ARG_VALUE    7
29 #define PROXIMITY_ARG_STATUS1  8
30 #define PROXIMITY_ARG_STATUS2  9
31
32 class GEOMImpl_IProximity
33 {
34 public:
35
36   GEOMImpl_IProximity(Handle(GEOM_Function) theFunction) : _func(theFunction) {}
37
38   void SetShapes(Handle(GEOM_Function) theShape1, Handle(GEOM_Function) theShape2)
39   {
40     _func->SetReference(PROXIMITY_ARG_SHAPE1, theShape1);
41     _func->SetReference(PROXIMITY_ARG_SHAPE2, theShape2);
42   }
43
44   void GetShapes(Handle(GEOM_Function)& theShape1, Handle(GEOM_Function)& theShape2) const
45   {
46     theShape1 = _func->GetReference(PROXIMITY_ARG_SHAPE1);
47     theShape2 = _func->GetReference(PROXIMITY_ARG_SHAPE2);
48   }
49
50   void SetNbSamples(const Standard_Integer thePosition, const Standard_Integer theNbSamples) const
51   {
52     _func->SetInteger(thePosition, theNbSamples);
53   }
54
55   Standard_Integer GetNbSamples(const Standard_Integer thePosition) const
56   {
57     return _func->GetInteger(thePosition);
58   }
59
60   void SetProximityPoints(const gp_Pnt& thePoint1, const gp_Pnt& thePoint2)
61   {
62     setPoint(PROXIMITY_ARG_POINT1, thePoint1);
63     setPoint(PROXIMITY_ARG_POINT2, thePoint2);
64   }
65
66   void SetStatusOfPoints(const Standard_Integer theStatus1, const Standard_Integer theStatus2)
67   {
68     setStatus(PROXIMITY_ARG_STATUS1, theStatus1);
69     setStatus(PROXIMITY_ARG_STATUS2, theStatus2);
70   }
71
72   void GetProximityPoints(gp_Pnt& thePoint1, gp_Pnt& thePoint2)
73   {
74     thePoint1 = getPoint(PROXIMITY_ARG_POINT1);
75     thePoint2 = getPoint(PROXIMITY_ARG_POINT2);
76   }
77
78   void GetStatusOfPoints(Standard_Integer& theStatus1, Standard_Integer& theStatus2)
79   {
80     theStatus1 = getStatus(PROXIMITY_ARG_STATUS1);
81     theStatus2 = getStatus(PROXIMITY_ARG_STATUS2);
82   }
83
84   void SetValue(const Standard_Real theValue)
85   {
86     _func->SetReal(PROXIMITY_ARG_VALUE, theValue);
87   }
88
89   Standard_Real GetValue() const
90   {
91     return _func->GetReal(PROXIMITY_ARG_VALUE);
92   }
93
94 private:
95   void setPoint(const Standard_Integer thePosition, const gp_Pnt& thePoint)
96   {
97     Handle(TColStd_HArray1OfReal) aCoords = new TColStd_HArray1OfReal(1, 3);
98     aCoords->SetValue(1, thePoint.X());
99     aCoords->SetValue(2, thePoint.Y());
100     aCoords->SetValue(3, thePoint.Z());
101     _func->SetRealArray(thePosition, aCoords);
102   }
103
104   void setStatus(const Standard_Integer thePosition, const Standard_Integer theStatus)
105   {
106     _func->SetInteger(thePosition, theStatus);
107   }
108
109   gp_Pnt getPoint(const Standard_Integer thePosition)
110   {
111     Handle(TColStd_HArray1OfReal) aCoords = _func->GetRealArray(thePosition);
112     return gp_Pnt(aCoords->Value(1), aCoords->Value(2), aCoords->Value(3));
113   }
114
115   Standard_Integer getStatus(const Standard_Integer thePosition)
116   {
117     return _func->GetInteger(thePosition);
118   }
119
120 private:
121   Handle(GEOM_Function) _func;
122 };