summaryrefslogtreecommitdiff
path: root/src/TestTopOpeDraw/TestTopOpeDraw_DrawableMesure.cxx
blob: 594f393fa9c819eb7a5224e3832099ced6bdfa64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
// File:	TestTopOpeDraw_DrawableMesure.cxx
// Created:	Thu Mar 13 16:23:47 1997
// Author:	Prestataire Mary FABIEN
//		<fbi@langdox.paris1.matra-dtv.fr>


#include <TestTopOpeDraw_DrawableMesure.ixx>
#include <TestTopOpeDraw_DrawableMesure.hxx>
#include <TestTopOpeDraw_DrawableP3D.hxx>
#include <TestTopOpeTools_Mesure.hxx>
#include <Geom_Curve.hxx>
#include <TopOpeBRepTool_CurveTool.hxx>
#include <Standard_CString.hxx>
#include <TColgp_Array1OfPnt.hxx>
#include <TColgp_HArray1OfPnt.hxx>
#include <string.h>
#include <Draw_Interpretor.hxx>


static gp_Pnt PScale(const gp_Pnt& P,
		     const Standard_Real ScaleX,
		     const Standard_Real ScaleY)
{
  gp_Pnt Pnt;
  Pnt.SetX(P.X() * ScaleX);
  Pnt.SetY(P.Y() * ScaleY);
  Pnt.SetZ(0.);
  return Pnt;
}

static TColgp_Array1OfPnt& Scale(const TColgp_Array1OfPnt& AP,
				 const Standard_Real ScaleX,
				 const Standard_Real ScaleY)
{
  Standard_Integer i,up = AP.Upper();
  TColgp_Array1OfPnt *aAP = new TColgp_Array1OfPnt(1, up);
  for (i = 1; i <= up;i++) { 
    aAP->SetValue(i, PScale(AP.Value(i), ScaleX, ScaleY));
  }
  return *aAP;
}

Handle(TColgp_HArray1OfPnt) makepnt(const TestTopOpeTools_Mesure& M,
				    Handle(TColgp_HArray1OfPnt) T)

{
  Standard_Integer up = T->Upper();
  TColgp_Array1OfPnt& AOP = T->ChangeArray1();
  const TColgp_Array1OfPnt& MAOP = M.Pnts();
  for(Standard_Integer i= 1; i <= up; i++) {
    AOP.SetValue(i,MAOP.Value(i));
  }
  return T;
}

Handle(TColgp_HArray1OfPnt) makepnt(const TestTopOpeTools_Mesure& M)

{
  Standard_Integer up = M.NPnts();
  Handle(TColgp_HArray1OfPnt) T = new TColgp_HArray1OfPnt(1,up);
  TColgp_Array1OfPnt& AOP = T->ChangeArray1();
  const TColgp_Array1OfPnt& MAOP = M.Pnts();
  for(Standard_Integer i= 1; i <= up; i++) {
    AOP.SetValue(i,MAOP.Value(i));
  }
  return T;
}

Handle(Geom_Curve) makecurvescale (const Handle(TColgp_HArray1OfPnt)& HP,
				   const Standard_Real ScaleX,
				   const Standard_Real ScaleY) 
{
  Handle(Geom_Curve) C;
  C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(Scale(HP->Array1(),ScaleX,ScaleY));
  return C;
}

Handle(Geom_Curve) makecurve(const Handle(TColgp_HArray1OfPnt)& HP)
{
  Handle(Geom_Curve) C;
  C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(HP->Array1());
  return C;
}


static Standard_CString makename(const TCollection_AsciiString C)
{
  char * temp = new char[C.Length()+2];
  temp[0] = ' ' ;
  temp[C.Length()+1] = 0;
  strncpy(&temp[1], C.ToCString(), C.Length());
  return temp;
}

static Standard_CString makename1(const gp_Pnt& P)
{
  TCollection_AsciiString C((Standard_Integer)P.Coord(1));

  char * temp = new char[C.Length()+2];
  temp[0]=' ';
  temp[C.Length()+1]=0;
  strncpy(&temp[1], C.ToCString(), C.Length());
  return temp;
}

static Standard_CString makename2(const gp_Pnt& P)
{
  TCollection_AsciiString C;

  C = "";C = C + P.Coord(2);
  TCollection_AsciiString S1 = C.Token(".",1);
  S1.RightJustify(15, ' ');
  TCollection_AsciiString S2 = C.Token(".",2);
  S2.Trunc(2);
  C = " ";C = C + S1 + "." + S2;

  char * temp = new char[C.Length()+1];
  temp[C.Length()]=0;
  strncpy(&temp[0], C.ToCString(), C.Length());
  return temp;
}

#ifdef DEB
static Handle(Geom_Curve) DrawAxe1(const TColgp_Array1OfPnt& T)
{
  Standard_Integer up = T.Upper();
  TColgp_Array1OfPnt *AOP = new TColgp_Array1OfPnt(1, up);
  for(Standard_Integer i= 1; i <= up; i++) {
    gp_Pnt pnt(T.Value(i).Coord(1), 0, 0);
    (*AOP).SetValue(i, pnt);
  }
  Handle(Geom_Curve) C;
  C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(*AOP);
  return C;
}
#endif

#ifdef DEB
static Handle(Geom_Curve) DrawAxe2(const TColgp_Array1OfPnt& T)
{
  Standard_Integer up = T.Upper();
  TColgp_Array1OfPnt *AOP = new TColgp_Array1OfPnt(1, up);
  for(Standard_Integer i= 1; i <= up; i++) {
    gp_Pnt pnt(0, T.Value(i).Coord(2), 0);
    (*AOP).SetValue(i, pnt);
  }
  Handle(Geom_Curve) C;
  C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(*AOP);
  return C;
}
#endif

static Handle(Geom_Curve) DrawAxe1(const TColgp_Array1OfPnt& T,
				   const Standard_Real ScaleX)
{
  Standard_Integer up = T.Upper();
  TColgp_Array1OfPnt *AOP = new TColgp_Array1OfPnt(1, up);
  for(Standard_Integer i= 1; i <= up; i++) {
    gp_Pnt pnt(T.Value(i).Coord(1) * ScaleX, 0, 0);
    (*AOP).SetValue(i, pnt);
  }
  Handle(Geom_Curve) C;
  C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(*AOP);
  return C;
}

static Handle(Geom_Curve) DrawAxe2(const TColgp_Array1OfPnt& T,
				   const Standard_Real ScaleY)
{
  Standard_Integer up = T.Upper();
  TColgp_Array1OfPnt *AOP = new TColgp_Array1OfPnt(1, up);
  for(Standard_Integer i= 1; i <= up; i++) {
    gp_Pnt pnt(0, T.Value(i).Coord(2) * ScaleY, 0);
    (*AOP).SetValue(i, pnt);
  }
  Handle(Geom_Curve) C;
  C = TopOpeBRepTool_CurveTool::MakeBSpline1fromPnt(*AOP);
  return C;
}

//=======================================================================
//function : TestTopOpeDraw_DrawableMesure
//purpose  : 
//=======================================================================

TestTopOpeDraw_DrawableMesure::TestTopOpeDraw_DrawableMesure
(const TestTopOpeTools_Mesure& M,
 const Draw_Color& CurveColor,
 const Draw_Color& TextColor,
 const Standard_Real ScaleX,
 const Standard_Real ScaleY) :
     TestTopOpeDraw_DrawableC3D(::makecurvescale(makepnt(M),ScaleX,ScaleY),
				  CurveColor, ::makename(M.Name())
				  , TextColor)
     ,myP(makepnt(M))
     ,myAXE1(new TestTopOpeDraw_DrawableC3D(DrawAxe1(myP->Array1(), ScaleX),
					      Draw_saumon))
     ,myAXE2(new TestTopOpeDraw_DrawableC3D(DrawAxe2(myP->Array1(), ScaleY),
					      Draw_saumon))
     ,myScaleX(ScaleX)
     ,myScaleY(ScaleY)
{
  Standard_Integer up = myP->Upper(), i;
  myHDP   = new TestTopOpeDraw_HArray1OfDrawableP3D(1,up);
  myHADP1 = new TestTopOpeDraw_HArray1OfDrawableP3D(1,up);
  myHADP2 = new TestTopOpeDraw_HArray1OfDrawableP3D(1,up);
  for(i = 1; i <= up; i++) {
    Handle(TestTopOpeDraw_DrawableP3D) DP
      = new TestTopOpeDraw_DrawableP3D(PScale(myP->Value(i), ScaleX, ScaleY),
					 Draw_rouge);
    myHDP->SetValue(i,DP);
    gp_Pnt PA1(myP->Value(i).Coord(1), 0, 0);
    gp_Pnt PA1Sc(myP->Value(i).Coord(1) * ScaleX, 0, 0);
    Handle(TestTopOpeDraw_DrawableP3D) DPA1
      = new TestTopOpeDraw_DrawableP3D(PA1Sc,Draw_rose,
					 makename1(PA1),Draw_rose,-7,15);
    myHADP1->SetValue(i,DPA1);
    gp_Pnt PA2(0,myP->Value(i).Coord(2), 0);
    gp_Pnt PA2Sc(0,myP->Value(i).Coord(2) * myScaleY, 0);
    Handle(TestTopOpeDraw_DrawableP3D) DPA2
      = new TestTopOpeDraw_DrawableP3D(PA2Sc,Draw_rose,
					 makename2(PA2),Draw_rose,-120,5);
    myHADP2->SetValue(i,DPA2);
  }
}

//=======================================================================
//function : SetScaleX
//purpose : 
//=======================================================================

void TestTopOpeDraw_DrawableMesure::SetScaleX(const Standard_Real ScaleX)
{ 
  SetScale(ScaleX, myScaleY);
}

//=======================================================================
//function : SetScaleY
//purpose : 
//=======================================================================

void TestTopOpeDraw_DrawableMesure::SetScaleY(const Standard_Real ScaleY)
{
  SetScale(myScaleX, ScaleY);
}

//=======================================================================
//function : SetScale
//purpose : 
//=======================================================================

void TestTopOpeDraw_DrawableMesure::SetScale(const Standard_Real ScaleX,
					     const Standard_Real ScaleY)
{
  myScaleX = ScaleX;
  myScaleY = ScaleY;
  Handle(Geom_Curve) GC = ::makecurvescale(myP, myScaleX, myScaleY);
  ChangeCurve(GC);
  ChangePnt(Pnt());
  GC = DrawAxe1(myP->Array1(), myScaleX);
  myAXE1->ChangeCurve(GC);
  myAXE1->ChangePnt(Pnt());
  GC = DrawAxe2(myP->Array1(), myScaleY);
  myAXE2->ChangeCurve(GC);
  myAXE2->ChangePnt(Pnt());
  Standard_Integer up = myP->Upper(), i;
  for(i = 1; i <= up; i++) {
    Handle(TestTopOpeDraw_DrawableP3D) DP = myHDP->Value(i);
    gp_Pnt P = PScale(myP->Value(i), myScaleX, myScaleY);
    DP->ChangePnt(P);
    myHDP->SetValue(i,DP);

    Handle(TestTopOpeDraw_DrawableP3D) DPA1 = myHADP1->Value(i);
    gp_Pnt PA1(myP->Value(i).Coord(1) * myScaleX, 0, 0);
    DPA1->ChangePnt(PA1);
    myHADP1->SetValue(i,DPA1);

    Handle(TestTopOpeDraw_DrawableP3D) DPA2 = myHADP2->Value(i);
    gp_Pnt PA2(0, myP->Value(i).Coord(2) * myScaleY, 0);
    DPA2->ChangePnt(PA2);
    myHADP2->SetValue(i,DPA2);
  }
}

//=======================================================================
//function : Pnt
//purpose : 
//=======================================================================

gp_Pnt TestTopOpeDraw_DrawableMesure::Pnt() const
{
  const Handle(Geom_Curve)& GC = DrawTrSurf_Curve::GetCurve();
  Standard_Real f = GC->FirstParameter();
  Standard_Real l = GC->LastParameter();
  Standard_Real t = 0.;
  Standard_Real p = t*f + (1-t)*l;
  gp_Pnt P = GC->Value(p);
  return P;
}

//=======================================================================
//function : Pnts
//purpose  : 
//=======================================================================

const Handle(TColgp_HArray1OfPnt)& TestTopOpeDraw_DrawableMesure::Pnts() const
{
  return myP;
}

//=======================================================================
//function : SetName
//purpose : 
//=======================================================================

void TestTopOpeDraw_DrawableMesure::SetName(const TCollection_AsciiString& Name)
{
  Standard_CString Str = makename(Name);
  ChangeText(Str);
}

//=======================================================================
//function : Clear
//purpose : 
//=======================================================================

void TestTopOpeDraw_DrawableMesure::Clear()
{
  myScaleX = 1;
  myScaleY = 1;
  
}

//=======================================================================
//function : Whatis
//purpose : 
//=======================================================================

void  TestTopOpeDraw_DrawableMesure::Whatis(Draw_Interpretor& s)const 
{
  if (!myP.IsNull())
    s << "DrawableMesure";
}

//=======================================================================
//function : DrawOn
//purpose : 
//=======================================================================

void TestTopOpeDraw_DrawableMesure::DrawOn(Draw_Display& dis) const
{
  Standard_Integer i,n;

  // les axes
  n = myHADP1->Upper();
  myAXE1->DrawOn(dis);
  for(i = 1; i <= n; i++) {
    myHADP1->Value(i)->DrawOn(dis);
  }

  myAXE2->DrawOn(dis);
  n = myHADP2->Upper();
  for(i = 1; i <= n; i++) {
    myHADP2->Value(i)->DrawOn(dis);
  }

  // la courbe et ses points
  TestTopOpeDraw_DrawableC3D::DrawOn(dis);
  n = myHDP->Upper();
  for(i = 1; i <= n; i++) {
    myHDP->Value(i)->DrawOn(dis);
    myHADP1->Value(i)->DrawOn(dis);
    myHADP2->Value(i)->DrawOn(dis);
  }
}