0022962: Invalid realization of reading and writing material in STEP.
[occt.git] / src / QADBMReflex / QADBMReflex_OCC749PrsUseVertexABV.cxx
1 // File:        QADBMReflex_OCC749PrsUseVertexABV.cxx
2 // Created:     Mon Oct  7 15:01:41 2002
3 // Author:      QA Admin
4 //              <qa@russox>
5
6
7 #include <QADBMReflex_OCC749PrsUseVertexABV.ixx>
8
9 #include <Prs3d_Root.hxx>
10 #include <Graphic3d_Group.hxx>
11 #include <Graphic3d_Vertex.hxx>
12 #include <Aspect_Array1OfEdge.hxx>
13 #include <Graphic3d_AspectFillArea3d.hxx>
14 #include <Graphic3d_MaterialAspect.hxx>
15 #include <Quantity_Color.hxx>
16 #include <Graphic3d_Array1OfVertexC.hxx>
17 #include <Aspect_Edge.hxx>
18
19
20 #include <Graphic3d_Array1OfVertex.hxx>
21 #include <OSD_Timer.hxx>
22
23 //=======================================================================
24 //function : QADBMReflex_OCC749PrsUseVertexABV
25 //purpose  : 
26 //=======================================================================
27
28   QADBMReflex_OCC749PrsUseVertexABV::QADBMReflex_OCC749PrsUseVertexABV( const Standard_Boolean Reflection,const Quantity_Color& InteriorColor,const Quantity_Color& EdgeColor,const Quantity_Color& EdgeColor2,const Standard_Integer XCount,const Standard_Integer YCount,const Standard_Integer BoxSize,const Graphic3d_MaterialAspect& MaterialAspect,const Standard_Boolean Material,const Standard_Boolean Timer ):QADBMReflex_OCC749Prs(Reflection,InteriorColor,EdgeColor,EdgeColor2,XCount,YCount,BoxSize,MaterialAspect,Material,Timer) {
29 }
30
31 static OSD_Timer Timer;
32
33 //=======================================================================
34 //function : Compute
35 //purpose  : 
36 //=======================================================================
37
38 void QADBMReflex_OCC749PrsUseVertexABV::Compute(const Handle(PrsMgr_PresentationManager3d)& aPrsMgr,
39                                              const Handle(Prs3d_Presentation)& aPresentation,
40                                              const Standard_Integer aMode )
41 {
42   Standard_Boolean BooleanTimer = GetTimer();
43   if (BooleanTimer) {
44     Timer.Reset ();
45     Timer.Start ();
46   }
47
48   aPresentation->Clear();
49   Handle(Graphic3d_Group) aGroup = Prs3d_Root::NewGroup(aPresentation);
50
51   Graphic3d_MaterialAspect aFlatMat; 
52   Standard_Boolean BooleanMaterial = GetMaterial();
53   if (BooleanMaterial) {
54     aFlatMat = GetMaterialAspect(); 
55   }
56
57   Standard_Boolean BooleanReflection = GetReflection();
58   if (BooleanReflection) {
59     aFlatMat.SetReflectionModeOn(Graphic3d_TOR_AMBIENT);
60     aFlatMat.SetReflectionModeOn(Graphic3d_TOR_DIFFUSE);
61     aFlatMat.SetReflectionModeOn(Graphic3d_TOR_SPECULAR);
62     aFlatMat.SetReflectionModeOn(Graphic3d_TOR_EMISSION);
63   } else {
64     aFlatMat.SetReflectionModeOff(Graphic3d_TOR_AMBIENT);
65     aFlatMat.SetReflectionModeOff(Graphic3d_TOR_DIFFUSE);
66     aFlatMat.SetReflectionModeOff(Graphic3d_TOR_SPECULAR);
67     aFlatMat.SetReflectionModeOff(Graphic3d_TOR_EMISSION);
68   }
69
70   Quantity_Color InteriorColor = GetInteriorColor();
71   Quantity_Color EdgeColor     = GetEdgeColor();
72   Standard_Integer XCOUNT = GetXCount();
73   Standard_Integer YCOUNT = GetYCount();
74   Standard_Integer BOXSIZE = GetBoxSize();
75
76   //Handle(Graphic3d_AspectFillArea3d) Fill3d;
77   //Fill3d = new Graphic3d_AspectFillArea3d(Aspect_IS_SOLID,
78         //                                InteriorColor,
79         //                                EdgeColor,
80         //                                Aspect_TOL_SOLID,
81         //                                1.5,
82         //                                aFlatMat,
83         //                                aFlatMat);
84
85   //aGroup->SetPrimitivesAspect(Fill3d);
86   aGroup->BeginPrimitives();
87
88   Standard_Integer i,j,z1=0,z2,zmax=XCOUNT;
89   if (YCOUNT > XCOUNT) zmax = YCOUNT;
90
91   Standard_Integer HMAX = 100;
92   BOXSIZE = HMAX / zmax;
93   if (BOXSIZE ==0)
94     BOXSIZE = 1;
95
96   for (i=0; i < XCOUNT; i++){
97     for (j=0; j < YCOUNT; j++){
98
99       //Quantity_NameOfColor aColor = Quantity_Color::Name(1., 
100       //                                                   (double)j/YCOUNT, 
101       //                                                   (double)i/XCOUNT);
102       Handle(Graphic3d_AspectFillArea3d) Fill3d = new Graphic3d_AspectFillArea3d(Aspect_IS_SOLID,
103                                               Quantity_Color(1., (double)j/YCOUNT, (double)i/XCOUNT, Quantity_TOC_RGB),
104                                               EdgeColor,
105                                               Aspect_TOL_SOLID,
106                                               1.5,
107                                               aFlatMat,
108                                               aFlatMat);
109       //////////////////if (i == 0 && j ==0) {
110         //////////////////Fill3d->SetInteriorColor(InteriorColor);
111       //////////////////}
112       aGroup->SetPrimitivesAspect(Fill3d);
113
114       Graphic3d_Array1OfVertex aVertexes(1, 8); 
115       
116       //////////////////z2 = BOXSIZE +(i*zmax - j*((Standard_Integer) zmax/2));
117       z2 = BOXSIZE +(i*BOXSIZE - j*BOXSIZE/2);
118       aVertexes(1).SetCoord(i*BOXSIZE, j*BOXSIZE, z1);
119       aVertexes(2).SetCoord(i*BOXSIZE + BOXSIZE, j*BOXSIZE, z1);
120       aVertexes(3).SetCoord(i*BOXSIZE + BOXSIZE, j*BOXSIZE + BOXSIZE, z1);
121       aVertexes(4).SetCoord(i*BOXSIZE, j*BOXSIZE + BOXSIZE, z1);
122       aVertexes(5).SetCoord(i*BOXSIZE, j*BOXSIZE, z2);
123       aVertexes(6).SetCoord(i*BOXSIZE + BOXSIZE, j*BOXSIZE, z2);
124       aVertexes(7).SetCoord(i*BOXSIZE + BOXSIZE, j*BOXSIZE + BOXSIZE, z2);
125       aVertexes(8).SetCoord(i*BOXSIZE, j*BOXSIZE + BOXSIZE, z2);
126
127       Aspect_Array1OfEdge aEdges(1, 24);
128       aEdges(1) = Aspect_Edge(1, 2, Aspect_TOE_VISIBLE);
129       aEdges(2) = Aspect_Edge(2, 3, Aspect_TOE_VISIBLE);
130       aEdges(3) = Aspect_Edge(3, 4, Aspect_TOE_VISIBLE);
131       aEdges(4) = Aspect_Edge(4, 1, Aspect_TOE_VISIBLE);
132
133       aEdges(5) = Aspect_Edge(5, 6, Aspect_TOE_VISIBLE);
134       aEdges(6) = Aspect_Edge(6, 7, Aspect_TOE_VISIBLE);
135       aEdges(7) = Aspect_Edge(7, 8, Aspect_TOE_VISIBLE);
136       aEdges(8) = Aspect_Edge(8, 5, Aspect_TOE_VISIBLE);
137
138       aEdges(9) = Aspect_Edge(1, 5, Aspect_TOE_VISIBLE);
139       aEdges(10) = Aspect_Edge(5, 6, Aspect_TOE_VISIBLE);
140       aEdges(11) = Aspect_Edge(6, 2, Aspect_TOE_VISIBLE);
141       aEdges(12) = Aspect_Edge(2, 1, Aspect_TOE_VISIBLE);
142
143       aEdges(13) = Aspect_Edge(6, 7, Aspect_TOE_VISIBLE);
144       aEdges(14) = Aspect_Edge(7, 3, Aspect_TOE_VISIBLE);
145       aEdges(15) = Aspect_Edge(3, 2, Aspect_TOE_VISIBLE);
146       aEdges(16) = Aspect_Edge(2, 6, Aspect_TOE_VISIBLE);
147
148       aEdges(17) = Aspect_Edge(3, 7, Aspect_TOE_VISIBLE);
149       aEdges(18) = Aspect_Edge(7, 8, Aspect_TOE_VISIBLE);
150       aEdges(19) = Aspect_Edge(8, 4, Aspect_TOE_VISIBLE);
151       aEdges(20) = Aspect_Edge(4, 3, Aspect_TOE_VISIBLE);
152
153       aEdges(21) = Aspect_Edge(4, 8, Aspect_TOE_VISIBLE);
154       aEdges(22) = Aspect_Edge(8, 5, Aspect_TOE_VISIBLE);
155       aEdges(23) = Aspect_Edge(5, 1, Aspect_TOE_VISIBLE);
156       aEdges(24) = Aspect_Edge(1, 4, Aspect_TOE_VISIBLE);
157
158       aGroup->QuadrangleSet(aVertexes, aEdges);
159     }
160   }
161   aGroup->EndPrimitives();
162
163   if (BooleanTimer) {
164     Timer.Stop ();
165     Timer.Show (cout);
166   }
167 }