1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 // Modified 10/04/98 : FMN ; Ajout include stdio.h pour WNT
19 #define PRO12324 // 03/07/98 : SYL ; bascule echo/pas echo pour test affichage et plotter
22 #define TEST_PARAGRAPH
25 #include <Graphic2d_GraphicObject.hxx>
26 #include <Graphic2d_Circle.hxx>
27 #include <Graphic2d_InfiniteLine.hxx>
28 #include <V2d_Viewer.hxx>
29 #include <TCollection_ExtendedString.hxx>
30 #include <Graphic2d_Text.hxx>
31 #include <Graphic2d_View.hxx>
32 #include <Graphic2d_FramedText.hxx>
33 #include <Graphic2d_HidingText.hxx>
34 #include <V2d_View.hxx>
35 #include <Graphic2d_InfiniteLine.hxx>
36 #include <Graphic2d_Segment.hxx>
37 #include <Graphic2d_CircleMarker.hxx>
38 #include <Graphic2d_Marker.hxx>
39 #include <Graphic2d_ViewMapping.hxx>
40 #include <Aspect_Units.hxx>
41 #include <Aspect_FontMap.hxx>
42 #include <Aspect_FontMapEntry.hxx>
43 #include <Aspect_FontStyle.hxx>
47 # include <OSD_Path.hxx>
48 # include <OSD_File.hxx>
49 # include <OSD_Protection.hxx>
50 # include <OSD_Environment.hxx>
51 # include <Graphic2d_ImageFile.hxx>
55 # include <Graphic2d_Paragraph.hxx>
56 # include <OSD_Environment.hxx>
57 #endif // TEST_PARAGRAPH
61 static char alphabet[]="abcdefghijklmnopqrstuvwzyz {}[]|`~!@#$%^&*()-_=+;:',<.>/?ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789";
62 static Standard_Boolean jeveuxecho = Standard_False;
63 static Standard_Boolean TestImage = Standard_False;
64 static Standard_Boolean TestPara = Standard_False;
66 void V2d::Draw(const Handle(V2d_Viewer)& aViewer)
68 Standard_Character txt[255];
69 Handle_Graphic2d_ViewMapping aViewMapping;
70 Handle(Graphic2d_GraphicObject) go = new Graphic2d_GraphicObject(aViewer->View());
73 OSD_Environment envImg ("CSF_V2D_TESTIMAGE");
75 if (!envImg.Value().IsEmpty ()) {
76 OSD_Protection Protection (OSD_R, OSD_R, OSD_R, OSD_R);
77 OSD_Path Path = OSD_Path (TCollection_AsciiString (envImg.Value ()), OSD_Default);
79 File.Open (OSD_ReadOnly, Protection);
82 TestImage = Standard_True;
87 Handle(Graphic2d_ImageFile) myImageFile;
88 // Add non-zoomable image to GO
89 myImageFile = new Graphic2d_ImageFile (go, File, -0.1 METER, -0.1 METER);
90 myImageFile -> SetZoomable (Standard_False);
91 myImageFile -> SetColorIndex (3);
93 // Add zoomable image to GO
94 myImageFile = new Graphic2d_ImageFile (go, File, 0.1 METER, 0.1 METER);
95 myImageFile -> SetZoomable (Standard_True);
98 Standard_Integer col = 1;
99 // Standard_Integer i,j;
101 Standard_Real ray = .10 METER;
102 for (i = 1; i<=20; i++) {
103 Handle(Graphic2d_Circle) c = new Graphic2d_Circle(go,0. METER,0. METER,ray);
104 c->SetColorIndex(col);
106 c->SetTypeOfPolygonFilling(Graphic2d_TOPF_EMPTY);
108 c->SetTypeOfPolygonFilling(Graphic2d_TOPF_FILLED);
110 c->SetTypeOfPolygonFilling(Graphic2d_TOPF_PATTERNED);
112 col = col < 10 ? col + 1 : 1;
118 #ifdef TEST_PARAGRAPH
119 OSD_Environment envPara ("CSF_V2D_PZOOM");
120 TestPara = (!envPara.Value ().IsEmpty());
121 if (!TestImage && TestPara) {
122 Handle(Graphic2d_Paragraph) myParagraph;
123 Handle(Graphic2d_HidingText) myHText;
125 TCollection_ExtendedString zText ("Zoomable Hiding Text");
126 TCollection_ExtendedString nzText ("Non-Zoomable Hiding Text");
127 TCollection_ExtendedString pstr1z ("Zoom Caracteres");
128 TCollection_ExtendedString pstr1nz ("Non-Zoom Caracteres");
129 TCollection_ExtendedString pstr21 ("Si vous ne goutez point ces");
130 TCollection_ExtendedString pstr22 ("je m'en etonne");
131 TCollection_ExtendedString pstr3 ("Mais si vous les goutez,je m'en etonne de meme");
132 TCollection_ExtendedString pstr4 ("La BRUYERE");
134 // Add non-zoomable paragraph in GO
136 new Graphic2d_Paragraph (go, 0. METER, 0. METER, 0.0, Aspect_CP_NorthEast, 0.7);
137 myParagraph -> SetFrameColorIndex (3);
138 myParagraph -> SetFrameWidthIndex (8);
139 myParagraph -> SetCurrentColorIndex (5);
140 myParagraph -> SetHidingColorIndex (9);
141 myParagraph -> SetZoomable (Standard_False);
143 myParagraph -> SetCurrentFontIndex (13);
144 myParagraph -> SetCurrentAlignment (Graphic2d_TOA_CENTER);
145 myParagraph -> SetCurrentUnderline (Standard_True);
146 myParagraph -> AddText(pstr1nz, 1);
148 myParagraph -> SetCurrentFontIndex (18);
149 myParagraph -> SetCurrentAlignment (Graphic2d_TOA_LEFT);
150 myParagraph -> SetCurrentUnderline (Standard_False);
151 myParagraph -> AddText(pstr21, 2);
153 myParagraph -> SetCurrentFontIndex (23);
154 myParagraph -> SetCurrentAlignment (Graphic2d_TOA_RIGHT);
155 myParagraph -> SetCurrentUnderline (Standard_True);
156 myParagraph -> AddText(pstr22, 3);
158 myParagraph -> SetCurrentFontIndex (27);
159 myParagraph -> SetCurrentAlignment (Graphic2d_TOA_LEFT);
160 myParagraph -> SetCurrentUnderline (Standard_False);
161 myParagraph -> AddText(pstr3, 4);
163 myParagraph -> SetCurrentFontIndex (2);
164 myParagraph -> SetCurrentAlignment (Graphic2d_TOA_RIGHT);
165 myParagraph -> SetCurrentUnderline (Standard_True);
166 myParagraph -> AddText(pstr4, 5);
168 // Add zoomable paragraph in GO
170 new Graphic2d_Paragraph (go, 0. METER, 0. METER, 0.0, Aspect_CP_SouthWest, 3.5);
171 myParagraph -> SetFrameColorIndex (3);
172 myParagraph -> SetFrameWidthIndex (8);
173 myParagraph -> SetCurrentColorIndex (5);
174 myParagraph -> SetZoomable (Standard_True);
176 myParagraph -> SetCurrentFontIndex (13);
177 myParagraph -> SetCurrentAlignment (Graphic2d_TOA_CENTER);
178 myParagraph -> SetCurrentUnderline (Standard_True);
179 myParagraph -> AddText(pstr1z, 1);
181 myParagraph -> SetCurrentFontIndex (18);
182 myParagraph -> SetCurrentAlignment (Graphic2d_TOA_LEFT);
183 myParagraph -> SetCurrentUnderline (Standard_False);
184 myParagraph -> AddText(pstr21, 2);
186 myParagraph -> SetCurrentFontIndex (23);
187 myParagraph -> SetCurrentAlignment (Graphic2d_TOA_RIGHT);
188 myParagraph -> SetCurrentUnderline (Standard_True);
189 myParagraph -> AddText(pstr22, 3);
191 myParagraph -> SetCurrentFontIndex (27);
192 myParagraph -> SetCurrentAlignment (Graphic2d_TOA_LEFT);
193 myParagraph -> SetCurrentUnderline (Standard_False);
194 myParagraph -> AddText(pstr3, 4);
196 myParagraph -> SetCurrentFontIndex (2);
197 myParagraph -> SetCurrentAlignment (Graphic2d_TOA_RIGHT);
198 myParagraph -> SetCurrentUnderline (Standard_True);
199 myParagraph -> AddText(pstr4, 5);
201 // Add zoomable hiding text to GO
202 myHText = new Graphic2d_HidingText (go, zText,
203 -0.25 METER, 0.25 METER, 0.0, 0.5, Aspect_TOT_SOLID, 10.);
204 myHText -> SetFrameWidthIndex (8);
205 myHText -> SetFrameColorIndex (1);
206 myHText -> SetHidingColorIndex (8);
207 myHText -> SetColorIndex (5);
208 myHText -> SetZoomable (Standard_True);
210 // Add non-zoomable hiding text to GO
211 myHText = new Graphic2d_HidingText (go, nzText,
212 0.25 METER, -0.25 METER, 0.0, 0.5, Aspect_TOT_SOLID, 2.);
213 myHText -> SetFrameWidthIndex (8);
214 myHText -> SetFrameColorIndex (1);
215 myHText -> SetHidingColorIndex (10);
216 myHText -> SetColorIndex (5);
217 myHText -> SetZoomable (Standard_False);
220 Standard_Integer col = 1;
221 // Standard_Integer i,j;
223 Standard_Real ray = .10 METER;
224 for (i = 1; i<=20; i++) {
225 Handle(Graphic2d_Circle) c = new Graphic2d_Circle (go, 0. METER, 0. METER, ray);
226 c -> SetColorIndex(col);
228 col = col < 12 ? col + 1 : 1;
232 Handle(Graphic2d_Marker) M;
233 Standard_ShortReal pos = -0.15 METER;
234 for (i = 1; i <= 12; i++) {
235 M = new Graphic2d_Marker(go, i, pos, pos, 0.005 METER,0.005 METER);
236 M -> SetColorIndex (i);
240 #endif // TEST_PARAGRAPH
242 if (!TestImage && !TestPara) {
244 // couleur de l' echo
245 Handle(Graphic2d_View) myGraphicView = aViewer->View();
246 myGraphicView->SetDefaultOverrideColor((Standard_Integer) 1);
248 Handle(Aspect_FontMap) theFontMap = aViewer->FontMap();
251 Standard_Real slant = 0.5;
252 Standard_Integer col = 1;
253 Standard_Integer typ ;
254 Standard_Integer wid ;
255 Standard_Integer i,j;
256 Handle(Graphic2d_Text) T;
257 Handle(Graphic2d_FramedText) TF;
258 Handle(Graphic2d_HidingText) TH;
259 Handle(Graphic2d_Segment) s;
262 cout << "Circle " << endl;
265 for ( i = 1; i<=20; i++) {
266 // cout << "ray=" << ray << " col=" << col << endl;
267 Handle(Graphic2d_Circle) c = new Graphic2d_Circle(go,0. METER,0. METER,ray);
268 c->SetColorIndex(col);
270 c->SetTypeOfPolygonFilling(Graphic2d_TOPF_EMPTY);
272 c->SetTypeOfPolygonFilling(Graphic2d_TOPF_FILLED);
274 c->SetTypeOfPolygonFilling(Graphic2d_TOPF_PATTERNED);
276 col = col < 10 ? col + 1 : 1;
286 cout << "Lines " << endl;
288 for ( i = 1; i<=8; i++) {
289 // Handle(Graphic2d_InfiniteLine) l = new Graphic2d_InfiniteLine(go, 0.0 METER, pos , pos , pos);
290 // l->SetColorIndex(col);
292 s = new Graphic2d_Segment(go, -0.6 METER, pos , -0.25 METER , pos);
293 s->SetColorIndex(col);
294 s->SetTypeIndex(typ);
295 s->SetWidthIndex(wid);
297 for ( j = 0; j<10; j++) {
298 s = new Graphic2d_Segment(go, -0.25 METER, post , -0.20 METER , post);
299 s->SetColorIndex(col);
304 col = col < 8 ? col + 1 : 1;
305 typ = typ < 4 ? typ + 1 : 1;
306 wid = wid < 8 ? wid + 1 : 1;
311 cout << "Markers " << endl;
313 Handle(Graphic2d_Marker) M ;
315 for ( i = 1; i<=13; i++) {
316 M = new Graphic2d_Marker(go,i,
318 0.005 METER,0.005 METER);
323 //Handle(TCollection_ExtendedString) txt = new TCollection_ExtendedString(alphabet);
327 cout << "Texts " << endl;
329 Standard_Integer nb = 30;
332 post = (0.05 + nb * 0.02) METER;
333 // traits verticaux tous les 10 mm
335 for ( i = 1; i<=40; i++) {
336 posh = (-0.15 + (i-1) * 0.01) METER;
337 s = new Graphic2d_Segment(go, posh , pos , posh , pos-post);
343 Aspect_FontMapEntry entry;
344 TCollection_AsciiString aname;
345 Aspect_FontStyle style;
346 Standard_Integer iindex;
347 nb = theFontMap->Size();
348 for ( i = 1; i<=nb; i++) {
350 entry = theFontMap->Entry(i) ;
351 iindex = entry.Index() ;
352 style = entry.Type();
353 aname = style.AliasName();
354 sprintf(txt,"Text Pol %d:%s:%s",iindex,aname.ToCString(),alphabet);
355 T = new Graphic2d_Text(go,
356 TCollection_ExtendedString(txt),
357 -0.15 METER, pos, 0.);
358 T->SetFontIndex(iindex);
359 T->SetColorIndex(col);
361 s = new Graphic2d_Segment(go, -0.2 METER, pos , 0.5 METER , pos);
366 sprintf(txt,"Hiding Text Pol %d:%s",iindex,alphabet);
367 TH = new Graphic2d_HidingText(go,
368 TCollection_ExtendedString(txt),
369 -0.15 METER, pos - post,
370 0. , 0.1 ,Aspect_TOT_SOLID);
371 TH->SetFontIndex(iindex);
372 TH->SetColorIndex(col);
374 TH->SetFrameColorIndex(col);
376 // Frame + Underline + Slant
377 sprintf(txt,"FramedText Pol %d",iindex);
378 TF = new Graphic2d_FramedText(go,
379 TCollection_ExtendedString(txt),
381 slant , 0.1 ,Aspect_TOT_SOLID);
382 TF->SetFontIndex(iindex);
383 TF->SetUnderline(Standard_True);
384 TF->SetColorIndex(col);
386 M = new Graphic2d_Marker(go,2,
388 0.005 METER,0.005 METER);
392 col = col < 8 ? col + 1 : 1;
395 sprintf(txt,"Texte non zoom Pol %d",i);
396 T = new Graphic2d_Text(go,
397 TCollection_ExtendedString(txt),
398 -0.3 METER, -0.22 METER ,
402 T->SetZoomable(Standard_False);
406 // bascule echo/pas echo
408 cout << "---- V2d ------ Highlight " << endl ;
409 go->Highlight( (Standard_Integer) 1);
410 jeveuxecho = Standard_False;
412 cout << "---- V2d ------ Display" << endl ;
414 jeveuxecho = Standard_True;