summaryrefslogtreecommitdiff
path: root/src/TestTopOpe/TestTopOpe_MesureCommands.cxx
blob: 12138fa3e21a526ae10ecb0316aad940793ce727 (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
// File:	TestTopOpe_BOOPCommands.cxx
// Created:	Mon Oct 21 10:32:36 1996
// Author:	Jean Yves LEBEY
//		<jyl@bistrox.paris1.matra-dtv.fr>

#include <TestTopOpe.ixx>

#include <Draw_Appli.hxx>
#include <Draw_Interpretor.hxx>
#include <TestTopOpeDraw_DrawableMesure.hxx>
#include <DrawTrSurf_Curve.hxx>

#include <TestTopOpeTools_Mesure.hxx>
#include <TestTopOpeTools_HArray1OfMesure.hxx>
#include <TestTopOpeDraw_Array1OfDrawableMesure.hxx>
#include <TColStd_Array1OfTransient.hxx>
#include <TColStd_Array1OfAsciiString.hxx>

#ifdef WNT
Standard_IMPORT Draw_Viewer dout;
#endif


//static Standard_Boolean Bool;
static Standard_Integer NbMES = 0;
static TColStd_Array1OfAsciiString *PDel = NULL;
static TColStd_Array1OfAsciiString *PNAME = NULL;
static TestTopOpeTools_Array1OfMesure *PAMES = NULL;

//-----------------------------------------------
static Standard_Integer SetName(const Standard_Character *C, Draw_Interpretor& di)
//-----------------------------------------------
// here the number of measurement is managed
{
  if(PNAME == NULL) { 
    PNAME = new TColStd_Array1OfAsciiString(1, 100);
  }
  if(PDel == NULL) { 
    PDel = new TColStd_Array1OfAsciiString(1, 100);
  }
  if(NbMES >= 100) {di << "ATTENTION : last measurement accepted";}
  for(Standard_Integer i = 1; i <= NbMES; i++) {
    Standard_Character *Ch = (Standard_Character *)(*PNAME).Value(i).ToCString();
    if( *Ch == *C) return i;
  }
  (*PNAME).SetValue(++NbMES, *C);
  (*PDel).SetValue(NbMES, "0");
  return NbMES;
}

// Unused :
#ifdef DEB
//-----------------------------------------------
static void SeemMesure(const Handle(TestTopOpeDraw_DrawableMesure) DM,const Standard_Integer CMES)
//-----------------------------------------------
{
  char *pname = (char *)(*PNAME).Value(CMES).ToCString();
  Draw::Set(pname,DM);
}
#endif

static void Mes_help(Draw_Interpretor& di)
{
  di<<"\n";
  di<<"mesure M : create/reset measurement M "<<"\n";
  di<<"mesure reset : reinitialize all measurements"<<"\n";
  di<<"mesure M n t : add data [n t] to M"<<"\n";
  di<<"mesure range M : sort indexes 'min max' of M"<<"\n";
  di<<"mesure minmax M : take 'xmin ymin xmax ymax' from M"<<"\n";
  di<<"mesure xy <i> M : take 'x y' = M(i)"<<"\n";
  di<<"seem M : visualize M"<<"\n";
  di<<"seemx M fx : visualize M with factor in x"<<"\n";
  di<<"seemx M fy : visualize M with factor in y"<<"\n";
  di<<"seemxy M fx fy : visualize M with factor in x,y"<<"\n";
  di<<""<<"\n";
}

// ----------------------------------------------------------------------
Standard_Integer Mes(Draw_Interpretor& di,Standard_Integer na, const char** a)
// ----------------------------------------------------------------------
{
  if (!strcmp(a[0],"mesure")) {
    if (na == 1) {
      Mes_help(di);
      return 0;
    }
    else if (na == 2) {
      if (!strcmp(a[1],"reset")) { PAMES = NULL; return 0;}
      else {
	Standard_Integer CurrentMES2 = SetName(a[1],di);
	TestTopOpeTools_Mesure *MES2;
	MES2 = new TestTopOpeTools_Mesure(a[1]);
	if(PAMES == NULL) { PAMES = new  TestTopOpeTools_Array1OfMesure(1, 100); }
	(*PAMES).SetValue(CurrentMES2, *MES2);
      }
    }
    else if (na == 3) {
      if      (!strcmp(a[1],"range")) {
	const TestTopOpeTools_Mesure& M = (*PAMES).Value(SetName(a[2],di));
	di<<"1 "<<M.NPnts();
      }
      else if (!strcmp(a[1],"minmax")) {
	const TestTopOpeTools_Mesure& M = (*PAMES).Value(SetName(a[2],di));
	Standard_Integer n=M.NPnts();
	Standard_Real xm=0,ym=0,xM=0,yM=0;
	if (n) {
	  xm=1.e100;ym=1.e100;xM=-1.e100;yM=-1.e100;
	  for (Standard_Integer i=1;i<=n;i++) {
	    Standard_Real x,y,z;gp_Pnt p=M.Pnt(i);p.Coord(x,y,z);
	    xm=Min(xm,x);xM=Max(xM,x);
	    ym=Min(ym,y);yM=Max(yM,y);
	  }
	}
	di<<xm<<" "<<ym<<" "<<xM<<" "<<yM;
      }
    }
    else if (na == 4) {
      if (!strcmp(a[1],"xy")) {
	Standard_Integer i = atoi(a[2]); 
	const TestTopOpeTools_Mesure& M = (*PAMES).Value(SetName(a[3],di));
	Standard_Real x,y,z;gp_Pnt p=M.Pnt(i);p.Coord(x,y,z);
	di<<x<<" "<<y;
	return 0;
      }
      Standard_Integer test2 = NbMES;
      Handle(Draw_Drawable3D) D = Draw::Get(a[1],Standard_False);
      Standard_Integer CurrentMES4 = SetName(a[1],di);
      if(PAMES == NULL) { PAMES = new  TestTopOpeTools_Array1OfMesure(1, 100); } 
      if((test2 < CurrentMES4) || // if nee measurement or if
	 (D.IsNull() && ((*PDel).Value(CurrentMES4) == "1"))) // after a "dall" 
	{ 
	  TestTopOpeTools_Mesure *MES4 = (new TestTopOpeTools_Mesure(a[1]));
	  (*MES4).Add(atoi(a[2]),atof(a[3]));
	  if((*PDel).Value(CurrentMES4) == "1") {
	    TestTopOpeTools_Mesure MES3;
	    MES3 = (*PAMES).Value(CurrentMES4);
	    MES3.Clear();
	  }
	  (*PDel).SetValue(CurrentMES4, "0");
	  (*PAMES).SetValue(CurrentMES4, *MES4);
	} else {
	  TestTopOpeTools_Mesure& MES4 = (*PAMES).ChangeValue(CurrentMES4);
	  MES4.Add(atoi(a[2]),atof(a[3]));
	  (*PAMES).SetValue(CurrentMES4, MES4);
	}
      
    }
  }
  else if (!strcmp(a[0],"seem")) {
    if (na < 2) return 0;
    TestTopOpeTools_Mesure MESS2;
    Handle(Draw_Drawable3D) D;
    Handle(TestTopOpeDraw_DrawableMesure) DMES2;
    Standard_Integer test4, CurrentMESS2, i;
    if(PAMES == NULL) { 
      PAMES = new  TestTopOpeTools_Array1OfMesure(1, 100); 
    }      
    for (i=1;i<na;i++) {
      test4 = NbMES;
      CurrentMESS2 = SetName(a[i],di);
      D = Draw::Get(a[i],Standard_False);
      if(test4 < CurrentMESS2) {// if nee measurement, it is after restore
	if(D.IsNull()) { return 0; }
	DMES2 = Handle(TestTopOpeDraw_DrawableMesure)::DownCast(D);
	TestTopOpeTools_Mesure *MES;
	MES = (new TestTopOpeTools_Mesure(DMES2->Pnts()));
	MES->SetName(a[i]);
	(*PAMES).SetValue(CurrentMESS2, *MES);
      } else {
	MESS2 = (*PAMES).Value(CurrentMESS2);
	if(!D.IsNull()) {
	  DMES2 = Handle(TestTopOpeDraw_DrawableMesure)::DownCast(D);
	} else { // --> M is already in PAMES, and DMES has no name
	  DMES2 = new TestTopOpeDraw_DrawableMesure(MESS2, Draw_blanc,Draw_rose);
	}
      }
      Draw::Set(a[i],DMES2);
      (*PDel).SetValue(CurrentMESS2, "1");
    }
    dout.RepaintAll();
  }
  else if (!strcmp(a[0],"seemx") || !strcmp(a[0],"seemy")) {
    if (na < 3) return 0;
    Standard_Real dx=1.,dy=1.;
    Standard_Boolean isX = Standard_False, isY = Standard_False;
    if      (!strcmp(a[0],"seemx")) { dx = atof(a[na-1]); isX = Standard_True; }
    else if (!strcmp(a[0],"seemy")) { dy = atof(a[na-1]); isY = Standard_True; }
    TestTopOpeTools_Mesure MES5;
    Handle(Draw_Drawable3D) D;
    Handle(TestTopOpeDraw_DrawableMesure) DMES5;
    Standard_Integer test, i;
    if(PAMES == NULL) { PAMES = new  TestTopOpeTools_Array1OfMesure(1, 100); }      
    for(i = 1; i < na-1; i++) {
      test = NbMES;
      Standard_Integer CurrentMES5 = SetName(a[i],di);
      D = Draw::Get(a[i],Standard_False);
      if(test < CurrentMES5) {// if new measurement, it is after restore
	if(D.IsNull()) { return 0; }
	DMES5 = Handle(TestTopOpeDraw_DrawableMesure)::DownCast(D);
	TestTopOpeTools_Mesure *MES;
	MES = (new TestTopOpeTools_Mesure(DMES5->Pnts()));
	MES->SetName(a[i]);
	(*PAMES).SetValue(CurrentMES5, *MES);
      } else {
	MES5 = (*PAMES).Value(CurrentMES5);
	if(!D.IsNull()) {
	  DMES5 = Handle(TestTopOpeDraw_DrawableMesure)::DownCast(D);
	} else {
	  DMES5 = new TestTopOpeDraw_DrawableMesure(MES5, Draw_blanc,Draw_rose);
	}
      }
      Draw::Set(a[i],DMES5);
      (*PDel).SetValue(CurrentMES5, "1");
      if(isX) DMES5->SetScaleX(dx);
      if(isY) DMES5->SetScaleY(dy);
    }
  }
  else if (!strcmp(a[0],"seemxy")) {
    if (na < 4) return 0;
    TestTopOpeTools_Mesure& M = (*PAMES).ChangeValue(SetName(a[1],di));
    Standard_Real dx=atof(a[2]),dy=atof(a[3]);
    Handle(Draw_Drawable3D) D = Draw::Get(a[1],Standard_False);
    Handle(TestTopOpeDraw_DrawableMesure) DM;
    DM = Handle(TestTopOpeDraw_DrawableMesure)::DownCast(D);
    if (DM.IsNull()) {
      DM = new TestTopOpeDraw_DrawableMesure(M,Draw_blanc,Draw_rose);
      Draw::Set(a[1],DM);
    }
    DM->SetScaleX(dx);
    DM->SetScaleY(dy);
    dout<<DM;
  }

  return 0;
}

void TestTopOpe::MesureCommands(Draw_Interpretor& theCommands)
     //=======================================================================
{
  const char* g = "Topological Operation Mesure commands";
  theCommands.Add("mesure","mesure M [n v] : create /add a data/ to a mesure",__FILE__,Mes,g);
  theCommands.Add("seem","seem M : visualize mesure M",__FILE__,Mes,g);
  theCommands.Add("seemx","seemx M ScaleX",__FILE__,Mes,g);
  theCommands.Add("seemy","seemy M ScaleY",__FILE__,Mes,g);
  theCommands.Add("seemxy","seemxy M ScaleX ScaleY",__FILE__,Mes,g);
}