0024755: TDF_Label::AddAttribute() reverses the order of added attributes
[occt.git] / tests / xcaf / end
1 puts "Test includes comparing for $CompareDocumentsMode"
2 ############## INIZIALIZING OF VARIABLES #################################
3 # ========== variables for comparison ======================
4 # Checkshape
5 set Checkshape_Second **
6 # Nbshapes
7 set nbDocVertex_Second **
8 set nbDocEdge_Second **
9 set nbDocWire_Second **
10 set nbDocFace_Second **
11 set nbDocShell_Second **
12 set nbDocSolid_Second **
13 set nbDocCompsolid_Second **
14 set nbDocCompound_Second **
15 set nbDocShape_Second **
16 # Faces
17 set faces_list_Second **
18 # Volumes
19 set DocLabels_Second **
20 set DocVolume_Second **
21 set r_Second **
22 set nbClosedShells_Second **
23 set DocVolume_Second **
24 # Colors
25 set DocAllColors_Second **
26 set DocShapeLabels_Second **
27 # Layers
28 set DocLayers_Second **
29 set DocLayerLabels_Second **
30 set DocShapeLabels_Second **
31 ###################################
32 # Checkshape
33 set Checkshape_First 0
34 # Nbshapes
35 set nbDocVertex_First 0
36 set nbDocEdge_First 0
37 set nbDocWire_First 0
38 set nbDocFace_First 0
39 set nbDocShell_First 0
40 set nbDocSolid_First 0
41 set nbDocCompsolid_First 0
42 set nbDocCompound_First 0
43 set nbDocShape_First 0
44 # Faces
45 set faces_list_First 0
46 # Volumes
47 set DocLabels_First 0
48 set DocVolume_First 0
49 set r_First 0
50 set nbClosedShells_First 0
51 set DocVolume_First 0
52 # Colors
53 set DocAllColors_First 0
54 set DocShapeLabels_First 0
55 # Layers
56 set DocLayers_First 0
57 set DocLayerLabels_First 0
58 set DocShapeLabels_First 0
59
60 # If it needs, adding to document D_First "Assembly colors and layers" OR "colors and layers"
61 if { [regexp "ASSEMBLY_C_L" $AddToDocument] } {
62     if { [info exists D_First] == 0} {
63         puts "Creating new doc"
64         XNewDoc D_First
65     }
66     ### colors' RGB
67     set color1  "1 0 0" ;# RED
68     set color2  "0 1 0" ;# GREEN
69     set color3  "0 0 1" ;# BLUE1
70     set color4  "1 1 0" ;# YELLOW
71     set color1c "0 1 1" ;# CYAN1
72     set color2c "1 0 1" ;# MAGENTA1
73     set color3c "1 1 1" ;# WHITE
74     set color4c "0 0 0" ;# BLACK
75     
76     ### colors' name
77     set color1name  RED
78     set color2name  GREEN
79     set color3name  BLUE1
80     set color4name  YELLOW
81     set color1cname CYAN1
82     set color2cname MAGENTA1
83     set color3cname WHITE
84     set color4cname BLACK
85     
86     ### Add compound in document as ASSEMBLY (default behaviour of XAddShape function)
87     box b1 10 10 10 
88     box b2 10 10 10 20 20 20 
89     compound b1 b2 c
90     XAddShape D_First c 
91     
92     ### Add free shape in document 
93     box b3 30 30 30 30 30 30
94     XAddShape D_First b3
95     ######################### COLORS VERIFYING ##############################
96     ### Add some colors in document
97     eval XAddColor D_First $color1
98     eval XAddColor D_First $color2
99     
100     ### Verify whether the collors are in document
101     if {[eval XFindColor D_First $color1] == "" || [eval XFindColor D_First $color1] == ""} {
102         puts "Error : Color was not added in the document or was not found after adding"
103         set ErrorCode 2
104     }
105     
106     ### Verify number of colors in document
107     if { [llength [XGetAllColors D_First]] != "2" } {
108         puts "Error : XGetAllColors function returns an invalid value"
109         set ErrorCode 2
110     }
111     
112     ### Assign color to shapes (two existing colors and six new colors)
113     # surfaces' colors
114     eval XSetColor D_First b1 $color1 s 
115     eval XSetColor D_First b2 $color2 s
116     eval XSetColor D_First b3 $color3 s
117     eval XSetColor D_First c  $color4 s
118     # curves' colors
119     eval XSetColor D_First b1 $color1c c 
120     eval XSetColor D_First b2 $color2c c
121     eval XSetColor D_First b3 $color3c c
122     eval XSetColor D_First c  $color4c c
123     ### Verify number of colors in document
124     if { [llength [XGetAllColors D_First]] != "8" } {
125         puts "Error : XGetAllColors function returns an invalid value after assigning colors to shapes in the document"
126         set ErrorCode 2
127     }
128     ### Verify colors of all shapes
129     if {[XGetShapeColor D_First [XFindShape D_First b1] s] != $color1name} {
130         puts "Error : Shape b1 has an invalid surface color "
131         set ErrorCode 2
132     }
133     if {[XGetShapeColor D_First [XFindShape D_First b2] s] != $color2name} {
134         puts "Error : Shape b2 has an invalid surface color "
135         set ErrorCode 2
136     }
137     if {[XGetShapeColor D_First [XFindShape D_First b3] s] != $color3name} {
138         puts "Error : Shape b3 has an invalid surface color "
139         set ErrorCode 2
140     }
141     if {[XGetShapeColor D_First [XFindShape D_First c ] s] != $color4name} {
142         puts "Error : Shape c has an invalid surface color "
143         set ErrorCode 2
144     }
145     if {[XGetShapeColor D_First [XFindShape D_First b1] c] != $color1cname} {
146         puts "Error : Shape b1 has an invalid surface color "
147         set ErrorCode 2
148     }
149     if {[XGetShapeColor D_First [XFindShape D_First b2] c] != $color2cname} {
150         puts "Error : Shape b2 has an invalid surface color "
151         set ErrorCode 2
152     }
153     if {[XGetShapeColor D_First [XFindShape D_First b3] c] != $color3cname} {
154         puts "Error : Shape b3 has an invalid surface color "
155         set ErrorCode 2
156     }
157     if {[XGetShapeColor D_First [XFindShape D_First c ] c] != $color4cname} {
158         puts "Error : Shape c has an invalid surface color
159         set ErrorCode 2
160     }
161     ### Remove some colors from document
162     # Remove colors of b1 surfaces 
163     XRemoveColor D_First [eval XFindColor D_First $color1]
164     # Remove colors of b2 curves 
165     XRemoveColor D_First [eval XFindColor D_First $color2c]
166     ### Verify number of colors in document
167     if { [llength [XGetAllColors D_First]] != "6" } {
168         puts "Error : XGetAllColors function returns an invalid value after removing two colors from the document"
169         set ErrorCode 2
170     }
171     ### Verify whether b1 and b2 have the removed colors 
172     if {[XGetShapeColor D_First [XFindShape D_First b1] s] != ""} {
173         puts "Error : Color of b1 surface was removed from the document however XGetShapeColor function returns value "
174         set ErrorCode 2
175     }
176     if {[XGetShapeColor D_First [XFindShape D_First b2] c] != ""} {
177         puts "Error : Color of b2 curves was removed from the document however XGetShapeColor function returns value "
178         set ErrorCode 2
179     }
180     ######################### LAYERS VERIFYING ##############################
181     ### Add three layers in document 
182     XAddLayer D_First L1
183     XAddLayer D_First L2
184     XAddLayer D_First L3
185     ### Verify amount layers in document
186     if { [llength [XGetAllLayers D_First]] != "3" } {
187         puts "Error : Error occurs during adding layers in document "
188         set ErrorCode 2
189     }
190     if { [llength [XGetLayerLabels D_First]] != "3" } {
191         puts "Error : XGetLayerLabels function works incorrectly  "
192         set ErrorCode 2
193     }
194     ### Verify whether the layers was added in document correctly
195     if { [XFindLayer D_First L1] == "" || [XFindLayer D_First L2] == "" || [XFindLayer D_First L3] == "" } {
196         puts "Error : Layers were not added in the document correctly "
197         set ErrorCode 2
198     }
199     ### Verify XGetOneLayer function
200     if { [XGetOneLayer D_First [XFindLayer D_First L1]] != "\"L1\"" } {
201         puts "Error : XGetOneLayer function works incorrectly for L1 layer"
202         set ErrorCode 2
203     }
204     if { [XGetOneLayer D_First [XFindLayer D_First L2]] != "\"L2\"" } {
205         puts "Error : XGetOneLayer function works incorrectly for L2 layer"
206         set ErrorCode 2
207     }
208     if { [XGetOneLayer D_First [XFindLayer D_First L3]] != "\"L3\"" } {
209         puts "Error : XGetOneLayer function works incorrectly for L3 layer"
210         set ErrorCode 2
211     }
212     ### Verify removing layer from document 
213     XAddLayer D_First LtoRemove
214     if { [llength [XGetAllLayers D_First]] != "4" } {
215         puts "Error : Error occurs when adding a layer in the document "
216         set ErrorCode 2
217     }
218     XRemoveLayer D_First LtoRemove
219     if { [llength [XGetAllLayers D_First]] != "3" } {
220         puts "Error : Error occurs when removing a layer from the document "
221         set ErrorCode 2
222     }
223     ### Verify interconnection layers and shapes
224     XSetLayer D_First b1 L1
225     XSetLayer D_First b2 L2
226     XSetLayer D_First b3 L3
227     XSetLayer D_First c  L3
228     if {[XGetLayers D_First b1] != "\"L1\" "} {
229         puts "Error : Shape b1 is not on layer L1" 
230         set ErrorCode 2
231     }
232     if {[XGetLayers D_First b2] != "\"L2\" "} {
233         puts "Error : Shape b2 is not on layer L2" 
234         set ErrorCode 2
235     }
236     if {[XGetLayers D_First b3] != "\"L3\" "} {
237         puts "Error : Shape b3 is not on layer L3"
238         set ErrorCode 2
239     }
240     if {[XGetLayers D_First c ] != "\"L3\" "} {
241         puts "Error : Compound c is not on layer L3" 
242         set ErrorCode 2
243     }
244     XRemoveColor D_First [eval XFindColor D_First $color4]
245     XRemoveColor D_First [eval XFindColor D_First $color4c]
246     XUnSetLayer D_First c L3
247
248
249 #================== COLORS_LAYER ===============
250 } elseif { [regexp "COLORS_LAYERS" $AddToDocument] } {
251     if {[info exists D_First] == 0} {
252         XNewDoc D_First
253     }
254     ### colors' RGB
255     set color1  "1 0 0" ;# RED
256     set color2  "0 1 0" ;# GREEN
257     set color3  "0 0 1" ;# BLUE1
258     set color4  "1 1 0" ;# YELLOW
259     set color1c "0 1 1" ;# CYAN1
260     set color2c "1 0 1" ;# MAGENTA1
261     set color3c "1 1 1" ;# WHITE
262     set color4c "0 0 0" ;# BLACK
263     
264     ### colors' name
265     set color1name  RED
266     set color2name  GREEN
267     set color3name  BLUE1
268     set color4name  YELLOW
269     set color1cname CYAN1
270     set color2cname MAGENTA1
271     set color3cname WHITE
272     set color4cname BLACK
273     ######################### COLORS VERIFYING ##############################
274     ### Add some colors in document
275     eval XAddColor D_First $color1
276     eval XAddColor D_First $color2
277     ### Verify whether the collors are in document
278     if {[eval XFindColor D_First $color1] == "" || [eval XFindColor D_First $color1] == ""} {
279         puts "Error : Color was not added in the document or was not found after adding"
280         set ErrorCode 2
281     }   
282     
283     ### Verify number of colors in document
284     if { [llength [XGetAllColors D_First]] != "2" } {
285         puts "Error : XGetAllColors function returns an invalid value"
286         set ErrorCode 2
287     }
288     set list [XGetTopLevelShapes D_First]
289     foreach {i} $list {
290         eval XSetColor D_First $i $color1 s
291         eval XSetColor D_First $i $color1c c
292     }
293     foreach {i} $list {
294         if {[XGetShapeColor D_First $i s] != $color1name} {
295             puts [format "Error : Shape  located on label %s has an invalid surface color " $i]
296             set ErrorCode 2
297         }
298         if {[XGetShapeColor D_First $i c] != $color1cname} {
299             puts [format "Error : Shape  located on label %s has an invalid curves color " $i]
300             set ErrorCode 2
301         }
302     }
303     ### Remove some colors from document
304     XRemoveColor D_First [eval XFindColor D_First $color1c]
305     ### Verify number of colors in document
306     if { [llength [XGetAllColors D_First]] != "2" } {
307         puts "Error : XGetAllColors function returns an invalid value after removing colors from the document"
308         set ErrorCode 2
309     }
310     
311     ### Verify shapes have the removed colors of curves
312     foreach {i} $list {
313         if {[XGetShapeColor D_First $i c] != ""} {
314             puts "Error : Curves color was removed from the document however XGetShapeColor function returns value "
315             set ErrorCode 2
316         }
317     }
318     ######################### LAYERS VERIFYING ##############################
319     ### Add three layers in document 
320     XAddLayer D_First L1
321     XAddLayer D_First L2
322     XAddLayer D_First L3
323     ### Verify amount layers in document
324     if { [llength [XGetAllLayers D_First]] != "3" } {
325         puts "Error : Error occurs when adding layers in the document  "
326         set ErrorCode 2
327     }
328     if { [llength [XGetLayerLabels D_First]] != "3" } {
329         puts "Error : XGetLayerLabels function works incorrectly  "
330         set ErrorCode 2
331     }
332     
333     ### Verify whether the layers were added in the document correctly
334     if { [XFindLayer D_First L1] == "" || [XFindLayer D_First L2] == "" || [XFindLayer D_First L3] == "" } {
335         puts "Error : Layers were not added in the document correctly "
336         set ErrorCode 2
337     }
338     
339     ### Verify XGetOneLayer function
340     if { [XGetOneLayer D_First [XFindLayer D_First L1]] != "\"L1\"" } {
341         puts "Error : XGetOneLayer function works incorrectly for L1 layer"
342         set ErrorCode 2
343     }
344     if { [XGetOneLayer D_First [XFindLayer D_First L2]] != "\"L2\"" } {
345         puts "Error : XGetOneLayer function works incorrectly for L2 layer"
346         set ErrorCode 2
347     }
348     if { [XGetOneLayer D_First [XFindLayer D_First L3]] != "\"L3\"" } {
349         puts "Error : XGetOneLayer function works incorrectly for L3 layer"
350         set ErrorCode 2
351     }
352     
353     ### Verify removing layer from document 
354     XAddLayer D_First LtoRemove
355     if { [llength [XGetAllLayers D_First]] != "4" } {
356         puts "Error : Error occurs when adding a layer in the document "
357         set ErrorCode 2
358     }
359     XRemoveLayer D_First LtoRemove
360     if { [llength [XGetAllLayers D_First]] != "3" } {
361         puts "Error : Error occurs when removing a layer from the document "
362         set ErrorCode 2
363     }
364     ### Verify interconnection layers and shapes
365     set aLen [llength $list]
366     for {set i 0} { $i < $aLen} {incr i} {
367         if { [expr $i / 2 == int ($i/2)] } { 
368             eval XSetLayer D_First [lindex $list $i] L1 
369         } else { 
370             eval XSetLayer D_First [lindex $list $i] L2
371         }
372     }
373     for {set i 0} { $i < $aLen} {incr i} {
374         if { [expr $i / 2 == int ($i/2)] } { 
375             set LLL "\"L1\" "
376         } else {
377             [set LLL "\"L2\" "]
378         }
379         if {[XGetLayers D_First [lindex $list $i]] != $LLL} {
380             puts [format "Error : Shape located on label %s  is not on layer %s" [lindex $list $i] $LLL]
381             set ErrorCode 2
382         }
383     }
384     XRemoveLayer D_First L2
385     XRemoveLayer D_First L3
386     XRemoveColor D_First [eval XFindColor D_First $color2]
387     set list [XGetTopLevelShapes D_First]
388     foreach {i} $list {
389         set str [XLabelInfo D_First $i]
390         if {[regexp "Assembly" $str] || [regexp "This Shape is not used" $str]} {
391             XUnSetLayer D_First $i L1
392             XUnsetColor D_First $i c
393             XUnsetColor D_First $i s
394         }
395     }
396     #erase all unused colors and layers
397     set list [XGetTopLevelShapes D_First]
398     set ColorIsUsed 0
399     set LayerIsUsed 0
400     foreach {i} $list {
401         set l [XGetShapeColor D_First $i c]
402         if {[expr [llength $l] != 0]} {
403             set ColorIsUsed 1
404         }
405         set l [XGetShapeColor D_First $i s]
406         if {[expr [llength $l] != 0]} {
407             set ColorIsUsed 1
408         }
409         set l [XGetLayers D_First $i]
410         if {[expr [llength $l] != 0]} {
411             set LayerIsUsed 1
412         }
413     }
414     if {$ColorIsUsed == 0} {
415         set label [XFindColor D_First 1 0 0 ]
416         XRemoveColor D_First $label
417     }
418     if {$LayerIsUsed == 0} {
419         XRemoveLayer D_First L1
420     }
421
422
423 # Get information for the first document
424 # Get shape for standard analysis
425 XGetOneShape res_First D_First
426 # Checkshape
427 if {[regexp "CHECKSHAPE" $CompareDocumentsMode]} {
428     set Checkshape_First [checkshape res_First]
429 }
430 # Nbshapes
431 if {[regexp "SHAPES" $CompareDocumentsMode] || [regexp "ALL" $CompareDocumentsMode]} {
432     set Stat_First [nbshapes res_First]
433     regexp {VERTEX +: +([-0-9.+eE]+)} $Stat_First full nbDocVertex_First
434     regexp {EDGE +: +([-0-9.+eE]+)} $Stat_First full nbDocEdge_First
435     regexp {WIRE +: +([-0-9.+eE]+)} $Stat_First full nbDocWire_First
436     regexp {FACE +: +([-0-9.+eE]+)} $Stat_First full nbDocFace_First
437     regexp {SHELL +: +([-0-9.+eE]+)} $Stat_First full nbDocShell_First
438     regexp {SOLID +: +([-0-9.+eE]+)} $Stat_First full nbDocSolid_First
439     regexp {COMPSOLID +: +([-0-9.+eE]+)} $Stat_First full nbDocCompsolid_First
440     regexp {COMPOUND +: +([-0-9.+eE]+)} $Stat_First full nbDocCompound_First
441     regexp {SHAPE +: +([-0-9.+eE]+)} $Stat_First full nbDocShape_First
442 }
443 # Faces
444 if {[regexp "FACES" $CompareDocumentsMode]} {
445     set type_of [dtyp res_First]
446     if {[regexp "FACE" $type_of] } {
447         set faces_list_First "FACE"
448     } else {
449         set faces_list_First [explode res_First F]
450     }
451 }
452 # Volumes
453 if {[regexp "VOLUME_EXACTLY" $CompareDocumentsMode] || [regexp "ALL" $CompareDocumentsMode]} {
454     set DocLabels_First [XGetFreeShapes D_First]
455     set DocVolume_First "0"
456     foreach {i} $DocLabels_First {
457         XSetProps D_First $i 1
458         set DocVolume_First [expr $DocVolume_First + abs([XGetVolume D_First $i])]
459     }
460 } elseif {[regexp "VOLUME" $CompareDocumentsMode]} {
461     set IsComp 0
462     XGetOneShape Shape_First D_First
463     set type [dtyp Shape_First]
464     puts $type
465     if {[regexp "SOLID" $type]} {
466         set IsComp 1
467     } elseif {[regexp "SHELL" $type] && [regexp "Orientable" $type] && [regexp "Closed" $type]} {
468         set IsComp 1
469     } elseif {[regexp "COMPOUND" $type]} {
470         set list [explode Shape_First So]
471         if {[llength $list] != 0} {
472             set IsComp 1
473         } 
474         set list [explode Shape_First Sh]
475         if {[llength $list] != 0} {
476             foreach {i} $list {
477                 set type [dtyp $i]
478                 if {[regexp "Orientable" $type] && [regexp "Closed" $type]} {
479                     set IsComp 1
480                 }
481             }
482         }
483     }
484     if {[expr $IsComp == 1]} {
485         XGetOneShape Shape_First D_First
486         catch { sewing r  0.00001 Shape_First}
487         set nbClosedShells_First 0
488         # Calculate amount of closed shells in initial shape
489         if {[regexp SHELL [whatis r]]} {
490             catch { fbclose r 0.001 0.00001 }
491             catch { if {[llength [explode r_o V]] == 0 && [llength [explode r_c V]] == 0}  {
492                 puts "nbClosedShells_First = 1"
493                 set nbClosedShells_First 1 } 
494             }
495         } else {
496             set shells [explode r Sh]
497             foreach {i} $shells { 
498                 catch { fbclose $i 0.001 0.00001}
499                 catch { 
500                     if { [llength [explode $i_o V]] == 0  && [llength [explode $i_c V]] == 0}  { 
501                         set nbClosedShells_First [expr $nbClosedShells_First + 1] 
502                     } 
503                 }
504             }
505         }
506         XNewDoc T_First
507         XAddShape T_First r
508         XSetProps T_First 0:1:1:1 1
509         set DocVolume_First [expr abs([XGetVolume T_First 0:1:1:1])]
510     } else {
511         puts "Volume of shape is equal 0"
512         set DocVolume_First 0
513         set nbClosedShells_First 0      
514     }
515 }
516 # Colors
517 if {[regexp "COLORS" $CompareDocumentsMode] || [regexp "ALL" $CompareDocumentsMode]} {
518     set DocAllColors_First   [lsort [XGetAllColors D_First]]
519     set DocShapeLabels_First  [XGetTopLevelShapes D_First]
520 }
521 # Layers
522 if { [regexp "LAYERS" $CompareDocumentsMode] || [regexp "ALL" $CompareDocumentsMode] || [regexp "LAYERS_EXACTLY" $CompareDocumentsMode] } {
523     set DocLayers_First [XGetAllLayers D_First] 
524     set DocLayerLabels_First [XGetLayerLabels D_First]
525     set DocShapeLabels_First [XGetTopLevelShapes D_First]
526 }
527 ################## WRITING FILE ##################"
528 ###Open temporary file
529 if { [string compare ${TypeOfFile} ""] == 0  } {
530     set saving [SaveAs D_First $WorkDirectory/${casename}_D_First.dxc]
531     set closing [Close D_First]
532     set opening [Open $WorkDirectory/${casename}_D_First.dxc D_Second]
533 } elseif {[string compare ${TypeOfFile} "igs"] == 0 } {
534     set writing [WriteIges D_First $WorkDirectory/${casename}_D_First.igs]
535     set reading [ReadIges D_Second $WorkDirectory/${casename}_D_First.igs]
536 } elseif {[string compare ${TypeOfFile} "stp"] == 0 } {
537     set writing [WriteStep D_First $WorkDirectory/${casename}_D_First.stp]
538     set reading [ReadStep D_Second $WorkDirectory/${casename}_D_First.stp]
539 } elseif {[string compare ${TypeOfFile} "brep"] == 0 } {
540     XGetOneShape Shape1 D_First
541     set saving [save Shape1 $WorkDirectory/${casename}_D_First.brep]
542     restore $WorkDirectory/${casename}_D_First.brep NewShape1 
543     XNewDoc D_Second
544     XAddShape D_Second NewShape1 
545 } else {
546     puts "Error : Wrong value of TypeOfFile"
547     set ErrorCode 2
548 }
549
550 if { [string compare ${TypeOfFile} ""] == 0  } {
551     catch {[file delete $WorkDirectory/${casename}_D_First.dxc]}
552 } elseif {[string compare ${TypeOfFile} "igs"] == 0 } {
553     catch {[file delete $WorkDirectory/${casename}_D_First.igs]}    
554 } elseif {[string compare ${TypeOfFile} "stp"] == 0} {
555     catch {[file delete $WorkDirectory/${casename}_D_First.stp]}
556 } elseif {[string compare ${TypeOfFile} "brep"] == 0} {
557     catch {[file delete $WorkDirectory/${casename}_D_First.brep]}
558 }
559 # Get information
560 # Get shape for standard analysis
561 XGetOneShape res_Second D_Second
562 # Checkshape
563 if {[regexp "CHECKSHAPE" $CompareDocumentsMode]} {
564     set Checkshape_Second [checkshape res_Second]
565 }
566 # Nbshapes
567 if {[regexp "SHAPES" $CompareDocumentsMode] || [regexp "ALL" $CompareDocumentsMode]} {
568     set Stat_Second [nbshapes res_Second]
569     regexp {VERTEX +: +([-0-9.+eE]+)} $Stat_Second full nbDocVertex_Second
570     regexp {EDGE +: +([-0-9.+eE]+)} $Stat_Second full nbDocEdge_Second
571     regexp {WIRE +: +([-0-9.+eE]+)} $Stat_Second full nbDocWire_Second
572     regexp {FACE +: +([-0-9.+eE]+)} $Stat_Second full nbDocFace_Second
573     regexp {SHELL +: +([-0-9.+eE]+)} $Stat_Second full nbDocShell_Second
574     regexp {SOLID +: +([-0-9.+eE]+)} $Stat_Second full nbDocSolid_Second
575     regexp {COMPSOLID +: +([-0-9.+eE]+)} $Stat_Second full nbDocCompsolid_Second
576     regexp {COMPOUND +: +([-0-9.+eE]+)} $Stat_Second full nbDocCompound_Second
577     regexp {SHAPE +: +([-0-9.+eE]+)} $Stat_Second full nbDocShape_Second
578 }
579 # Faces
580 if {[regexp "FACES" $CompareDocumentsMode]} {
581     set type_of [dtyp res_Second]
582     if {[regexp "FACE" $type_of] } {
583         set faces_list_Second "FACE"
584     } else {
585         set faces_list_Second [explode res_Second F]
586     }
587 }
588 # Volumes
589 if {[regexp "VOLUME_EXACTLY" $CompareDocumentsMode] || [regexp "ALL" $CompareDocumentsMode]} {
590     set DocLabels_Second [XGetFreeShapes D_Second]
591     set DocVolume_Second "0"
592     foreach {i} $DocLabels_Second {
593         XSetProps D_Second $i 1
594         set DocVolume_Second [expr $DocVolume_Second + abs([XGetVolume D_Second $i])]
595     }
596 } elseif {[regexp "VOLUME" $CompareDocumentsMode]} {
597     if {[expr $IsComp == 1]} {
598         # Perform sewing of resulting shape. If amount of closed shells of resulting shape is not equal to amount of 
599         # closed shells of initial shape increace tolerance and perform sewing again
600         set nbClosedShells_Second 0
601         set toler 0.00001
602         set IsSewingPerformedCorrectly 0
603         XGetOneShape Shape_Second D_Second
604         for {set k 0} {$k < 5} {incr k} {
605             # 1. Perform sewing
606             puts [format "PERFORM SEWING. TOLERANCE = %f" $toler]
607             catch { sewing res $toler Shape_Second }
608             # 2. Calculate amount of closed shells
609             set nbClosedShells_Second 0
610             if {[regexp SHELL [whatis res]]} {
611                 catch { fbclose res 0.001 $toler }
612                 catch { 
613                     if {[llength [explode res_o V]] == 0 && [llength [explode res_c V]] == 0 }  { 
614                         set nbClosedShells_Second 1 
615                     } 
616                 }
617             } else {
618                 set shells [explode res Sh]
619                 foreach i $shells { 
620                     catch { fbclose $i 0.001 0.000001 }
621                     catch { 
622                         if {[llength [explode $i_o V]] == 0 && [llength [explode $i_c V]] == 0}  { 
623                             set nbClosedShells_Second [expr $nbClosedShells_Second +1] 
624                         }  
625                     }
626                 }       
627             }
628             # 3. Verify amount of closed shells
629                 if { $nbClosedShells_Second >= $nbClosedShells_First} { 
630                     set IsSewingPerformedCorrectly 1 
631                     break
632                 }
633             # 4. Set new tolerance
634             set toler [expr $toler * 10]
635         }
636         XNewDoc T_Second
637         XAddShape T_Second res;
638         XSetProps T_Second 0:1:1:1 1;
639         set DocVolume_Second [expr abs([XGetVolume T_Second 0:1:1:1])]
640         if { $IsSewingPerformedCorrectly == 0 } {
641             puts "Error : SEWING IS NOT PERFORMED PROPERLY"
642         }
643     } else {
644         puts "Volume of shape is equal 0"
645         set DocVolume_Second 0
646         set nbClosedShells_Second 0
647     }
648 }
649 # Colors
650 if {[regexp "COLORS" $CompareDocumentsMode] || [regexp "ALL" $CompareDocumentsMode]} {
651     set DocAllColors_Second   [lsort [XGetAllColors D_Second]]
652     set DocShapeLabels_Second  [XGetTopLevelShapes D_Second]
653 }
654 # Layers
655 if { [regexp "LAYERS" $CompareDocumentsMode] || [regexp "ALL" $CompareDocumentsMode] || [regexp "LAYERS_EXACTLY" $CompareDocumentsMode] } {
656     set DocLayers_Second [XGetAllLayers D_Second]       
657     set DocLayerLabels_Second [XGetLayerLabels D_Second]
658     set DocShapeLabels_Second [XGetTopLevelShapes D_Second]
659 }
660 puts "====================RESULTS OF COMPARISON===================="
661 if {[regexp "CHECKSHAPE" $CompareDocumentsMode]} {
662     puts "====================CHECKSHAPE==============="
663     puts "First : $Checkshape_First"
664     puts "Second : $Checkshape_Second"
665     if {[string compare $Checkshape_First $Checkshape_Second] != 0} {
666         puts "Error : checkshape is wrong"
667         set ErrorCode 2
668     }
669 }
670 if {[regexp "SHAPES" $CompareDocumentsMode] || [regexp "ALL" $CompareDocumentsMode]} {
671     puts "====================SHAPES==============="
672     puts "Vertex First: $nbDocVertex_First"
673     puts "Vertex Second: $nbDocVertex_Second"
674     if {[string compare $nbDocVertex_First $nbDocVertex_Second] != 0} {
675         puts "Error : nbshapes is wrong"
676         set ErrorCode 2
677     }
678     puts "Edge First: $nbDocEdge_First"
679     puts "Edge Second: $nbDocEdge_Second"
680     if {[string compare $nbDocEdge_First $nbDocEdge_Second] != 0} {
681         puts "Error : nbshapes is wrong"
682         set ErrorCode 2
683     }
684     puts "Wire First: $nbDocWire_First"
685     puts "Wire Second: $nbDocWire_Second"
686     if {[string compare $nbDocWire_First $nbDocWire_Second] != 0} {
687         puts "Error : nbshapes is wrong"
688         set ErrorCode 2
689     }
690     puts "Face First: $nbDocFace_First"
691     puts "Face Second: $nbDocFace_Second"
692     if {[string compare $nbDocFace_First $nbDocFace_Second] != 0} {
693         puts "Error : nbshapes is wrong"
694         set ErrorCode 2
695     }
696     puts "Shell First: $nbDocShell_First"
697     puts "Shell Second: $nbDocShell_Second"
698     if {[string compare $nbDocShell_First $nbDocShell_Second] != 0} {
699         puts "Error : nbshapes is wrong"
700         set ErrorCode 2
701     }
702     puts "Solid First: $nbDocSolid_First"
703     puts "Solid Second: $nbDocSolid_Second"
704     if {[string compare $nbDocSolid_First $nbDocSolid_Second] != 0} {
705         puts "Error : nbshapes is wrong"
706         set ErrorCode 2
707     }
708     puts "Compsolid First: $nbDocCompsolid_First"
709     puts "Compsolid Second: $nbDocCompsolid_Second"
710     if {[string compare $nbDocCompsolid_First $nbDocCompsolid_Second] != 0} {
711         puts "Error : nbshapes is wrong"
712         set ErrorCode 2
713     }
714     puts "Compound First: $nbDocCompound_First"
715     puts "Compound Second: $nbDocCompound_Second"
716     if {[string compare $nbDocCompound_First $nbDocCompound_Second] != 0} {
717         puts "Error : nbshapes is wrong"
718         set ErrorCode 2
719     }
720     puts "Shape First: $nbDocShape_First"
721     puts "Shape Second: $nbDocShape_Second"
722     if {[string compare $nbDocShape_First $nbDocShape_Second] != 0} {
723         puts "Error : nbshapes is wrong"
724         set ErrorCode 2
725     }
726 }
727 if {[regexp "FACES" $CompareDocumentsMode]} {
728     puts "================FACES==================="
729     puts "Faces First: [llength $faces_list_First]"
730     puts "Faces Second: [llength $faces_list_Second]"
731     if {[llength $faces_list_First] != [llength $faces_list_Second]} {
732         puts "Error : The number of faces is wrong"
733         set ErrorCode 2
734     }
735 }
736 if {[regexp "VOLUME_EXACTLY" $CompareDocumentsMode] || [regexp "ALL" $CompareDocumentsMode]} {
737     puts "===============VOLUME_EXACTLY===================="
738     puts "DocLabels First: $DocLabels_First"
739     puts "DocLabels Second: $DocLabels_Second"
740     if {[string compare $DocLabels_First $DocLabels_Second] != 0} {
741         puts "Error : DocLabels are wrong"
742         set ErrorCode 2
743     }
744     puts "DocVolume First: $DocVolume_First"
745     puts "DocVolume Second: $DocVolume_Second"
746     if {[string compare $DocVolume_First $DocVolume_Second] != 0} {
747         set MaxVolume [expr  $DocVolume_First> $DocVolume_Second ? $DocVolume_First : $DocVolume_Second]
748         if {[expr $MaxVolume > 0]} {
749             set diff [ expr abs($DocVolume_First-$DocVolume_Second)/ $MaxVolume * 100 ] 
750         } else {
751             set diff 0
752         }
753         if {[expr $diff > 5]} {
754             puts [format "Error : The difference between volumes is %f%s" $diff "%"]
755             set ErrorCode 2
756         } else {
757             puts [format "The difference between volumes is %f%s - OK" $diff "%"] 
758         }
759     }
760 } elseif {[regexp "VOLUME" $CompareDocumentsMode]} {
761     puts "===============VOLUME===================="
762     puts "DocVolume First: $DocVolume_First"
763     puts "DocVolume Second: $DocVolume_Second"
764     if {[string compare $DocVolume_First $DocVolume_Second] != 0} {
765         set MaxVolume [expr  $DocVolume_First> $DocVolume_Second ? $DocVolume_First : $DocVolume_Second]
766         if {[expr $MaxVolume > 0]} {
767             set diff [ expr abs($DocVolume_First-$DocVolume_Second)/ $MaxVolume * 100 ] 
768         } else {
769             set diff 0
770         }
771         if {[expr $diff > 5]} {
772             puts [format "Error : The difference between volumes is %f%s" $diff "%"]
773             set ErrorCode 2
774         } else {
775             puts [format "The difference between volumes is %f%s - OK" $diff "%"] 
776         }
777     }
778     puts "nbClosedShells First: $nbClosedShells_First"
779     puts "nbClosedShells Second: $nbClosedShells_Second"
780     if {[string compare $nbClosedShells_First $nbClosedShells_Second] != 0} {
781         puts "Error : nbClosedShells is wrong"
782         set ErrorCode 2
783     }
784 }
785 if {[regexp "COLORS" $CompareDocumentsMode] || [regexp "ALL" $CompareDocumentsMode]} {
786     puts "==============COLORS====================="
787     puts "DocAllColors First: $DocAllColors_First"
788     puts "DocAllColors Second: $DocAllColors_Second"
789     if {[llength $DocAllColors_Second] == 0 && [llength $DocAllColors_First] != 0} {
790         puts "Warning : There are no colors in D_Second although they are present in D_First"
791         if {[expr $ErrorCode == 0]} { 
792             set ErrorCode 1     
793         }
794     }
795     if {[regexp "COLORS_EXACTLY" $CompareDocumentsMode] || [regexp "ALL" $CompareDocumentsMode]} {
796         if {[string compare $DocAllColors_First $DocAllColors_Second] != 0} {
797             puts "Error : Compared documents have a different set of colors"
798             set ErrorCode 2
799         }
800     }
801     puts "DocShapeLabels First: $DocShapeLabels_First"
802     puts "DocShapeLabels Second: $DocShapeLabels_Second"
803     if {[string compare $DocShapeLabels_First $DocShapeLabels_Second] != 0} {
804         if {[regexp "ALL" $CompareDocumentsMode]} {
805             set ErrorCode 2
806             puts "Error : Compared documents have a different number of toplevel shapes "
807         } else { 
808             puts "Warning : Compared documents have a different number of toplevel shapes "
809             if {[expr $ErrorCode == 0]} { 
810                 set ErrorCode 1
811             }
812         }
813     }
814 }
815 if { [regexp "LAYERS" $CompareDocumentsMode] || [regexp "ALL" $CompareDocumentsMode] || [regexp "LAYERS_EXACTLY" $CompareDocumentsMode] } {
816     puts "================LAYERS==================="
817     
818     puts "DocLayers First: $DocLayers_First"
819     puts "DocLayers Second: $DocLayers_Second"
820     if {[string compare $DocLayers_First $DocLayers_Second] != 0} {
821         if {[regexp "LAYERS_EXACTLY" $CompareDocumentsMode]} {
822             set ErrorCode 2
823             puts "Error : Compared documents have a different set of LAYERS names"
824         } else { 
825             puts "Warning : Compared documents have a different set of LAYERS names"
826             if {[expr $ErrorCode == 0]} { 
827                 set ErrorCode 1 
828             }
829         }
830     }
831     puts "DocLayerLabels First: $DocLayerLabels_First"
832     puts "DocLayerLabels Second: $DocLayerLabels_Second"
833     if {[string compare $DocLayerLabels_First $DocLayerLabels_Second] != 0} {
834         if {[regexp "LAYERS_EXACTLY" $CompareDocumentsMode]} {
835             puts [format "Error : Compared documents have a different set of LAYERS labels"]
836             set ErrorCode 2
837         } else {
838             puts [format "Warning : Compared documents have a different set of LAYERS labels"]
839             if {[expr $ErrorCode == 0]} { 
840                 set ErrorCode 1 
841             }
842         }
843     }
844     puts "DocShapeLabels First: $DocShapeLabels_First"
845     puts "DocShapeLabels Second: $DocShapeLabels_Second"
846     if {[string compare $DocShapeLabels_First $DocShapeLabels_Second] != 0} {
847         if {[regexp "ALL" $CompareDocumentsMode]} {
848             puts "Error : DocShapeLabels is wrong"
849             set ErrorCode 2
850         } else {
851             puts "Warning : DocShapeLabels is wrong"
852             set ErrorCode 1
853         }
854     }
855     if {[regexp "LAYERS_EXACTLY" $CompareDocumentsMode]} {
856         set DDD $DocLayers_First
857         if {$DocLayers_First > $DocLayers_Second} {
858             set DDD $DocLayers_Second
859         }
860         foreach {i} $DDD {
861             set DocLabel_First [XFindLayer D_First $i]
862             set DocLabel_Second [XFindLayer D_Second $i]
863
864             if {[string compare $DocLabel_First $DocLabel_Second] != 0} {
865                 puts [format "   DocLabel_First(%s) = %s " $i $DocLabel_First]
866                 puts [format "  DocLabel_Second(%s) = %s " $i $DocLabel_Second]
867                 puts [format "Error : Compared documents have different labels for one layer (%s)" $i]
868                 set ErrorCode 2
869             }
870         }
871         
872         set DocShapeLabels_First [XGetTopLevelShapes D_First]
873         set DocShapeLabels_Second [XGetTopLevelShapes D_Second]
874         
875         set DDD $DocShapeLabels_First
876         if {$DocShapeLabels_First > $DocShapeLabels_Second} {
877             set DDD $DocShapeLabels_Second
878         }
879         foreach {i} $DDD {
880             set DocLayer_First [XGetLayers D_First $i]
881             set DocLayer_Second [XGetLayers D_Second $i]
882
883             if {[string compare $DocLayer_First $DocLayer_Second] != 0} {
884                 set NewLabel "$i:1"
885                 set DocLayer_Second [XGetLayers D_Second $NewLabel]
886             }
887             
888             if {[string compare $DocLayer_Second $DocLayer_First] != 0} {
889                 puts [format " DocLayer_First(%s) = %s " $i $DocLayer_First]
890                 puts [format "DocLayer_Second(%s) = %s " $i $DocLayer_Second]
891                 puts [format "DocLayer_Second(%s) = %s " $NewLabel $DocLayer_Second]
892                 puts [format "Error : Compared documents have different LAYERS for the shape located on %s label" $i]
893                 set ErrorCode 2
894             }
895         }
896         
897         set DDD $DocLayerLabels_First
898         if {$DocLayerLabels_First > $DocLayerLabels_Second} {
899             set DDD $DocLayerLabels_Second
900         }
901         foreach {i} $DDD {
902             set LayerName_First [XGetOneLayer D_First $i]
903             set LayerName_Second [XGetOneLayer D_Second $i]
904
905             if {[string compare $LayerName_First $LayerName_Second]!=0} {
906                 set NewLabel "$i:1"
907                 set LayerName_Second [XGetOneLayer D_Second $NewLabel]
908             }
909             if {[string compare $LayerName_Second $LayerName_First]!=0} {
910                 puts [format " LayerName_First(%s) = %s " $i $LayerName_First]
911                 puts [format "LayerName_Second(%s) = %s " $i $LayerName_Second]
912                 puts [format "LayerName_Second(%s) = %s " $NewLabel $LayerName_Second]
913                 puts [format "Error : Compared documents have different LAYERS names on %s label" $i]
914                 set ErrorCode 2
915             }
916         }
917     }
918 }    
919
920 XGetOneShape result D_Second
921 if {[isdraw result]} {
922     clear
923     smallview
924     donly result
925     fit
926     xwd $imagedir/${test_image}.png
927 }
928
929 if {[expr $ErrorCode == 2]} { 
930     puts "Error : errors occur during test"
931 } elseif {[expr $ErrorCode == 1]} { 
932     puts "WARNING OCCURS DURING TEST"
933 } elseif {[expr $ErrorCode != 0]} {
934     puts "Error : a wrong value of ErrorCode."
935 }
936
937 puts "TEST COMPLETED"