1 // Viewer2dDoc.cpp : implementation of the CViewer2dDoc class
5 #include "Viewer2dDoc.h"
7 #include "Primitive\Sample2D_Markers.h"
8 #include "Primitive\Sample2D_Text.h"
9 #include "Primitive\Sample2D_Face.h"
10 #include "Primitive\Sample2D_Image.h"
12 /////////////////////////////////////////////////////////////////////////////
15 IMPLEMENT_DYNCREATE(CViewer2dDoc, CDocument)
17 BEGIN_MESSAGE_MAP(CViewer2dDoc, CDocument)
18 //{{AFX_MSG_MAP(CViewer2dDoc)
19 ON_COMMAND(ID_BUTTON_Test_Text, OnBUTTONTestText)
20 ON_COMMAND(ID_BUTTON_Test_Markers, OnBUTTONTestMarkers)
21 ON_COMMAND(ID_BUTTON_Test_Line, OnBUTTONTestLine)
22 ON_COMMAND(ID_BUTTON_Erase, OnBUTTONErase)
23 ON_COMMAND(ID_BUTTON_Test_Face, OnBUTTONTestFace)
24 ON_COMMAND(ID_BUTTON_Test_Rect, OnBUTTONTestRect)
25 ON_COMMAND(ID_BUTTON_Test_Curve, OnBUTTONTestCurve)
26 ON_COMMAND(ID_BUTTON32793, OnBUTTONTestImage) // test image
27 ON_COMMAND(ID_BUTTON_Test_MultiImages, OnBUTTONMultipleImage)
32 /////////////////////////////////////////////////////////////////////////////
33 // CViewer2dDoc construction/destruction
35 CViewer2dDoc::CViewer2dDoc()
39 CViewer2dDoc::~CViewer2dDoc()
44 void CViewer2dDoc::AssertValid() const
46 CDocument::AssertValid();
49 void CViewer2dDoc::Dump(CDumpContext& dc) const
55 /////////////////////////////////////////////////////////////////////////////
56 // CViewer2dDoc commands
58 void CViewer2dDoc::OnBUTTONErase()
60 if(myAISContext->HasOpenedContext())
61 myAISContext->CloseAllContexts();
62 myAISContext->EraseAll();
65 void CViewer2dDoc::OnBUTTONTestText()
71 TCollection_AsciiString Text("font 0 scale ");Text+=j/20.0;
72 Handle (Sample2D_Text) aText =
73 new Sample2D_Text(Text,
74 gp_Pnt(0.0,15.0*(j-15.0),0.0), // thePosition
75 Aspect_TOT_SOLID, // theType
76 10.0*M_PI, // theAngle
77 (Quantity_NameOfColor)(aColor++), // theColor
78 Font_FA_Regular, // theFontAspect
83 Standard_False); // aIsZoomable
85 myAISContext->Display(aText, Standard_False);
90 TCollection_AsciiString Text("font 1 scale ");Text+=j/10.0;
91 Handle (Sample2D_Text) aText =
92 new Sample2D_Text(Text,
93 gp_Pnt(80.,15.0*(j-10.0),0.0), // thePosition
94 Aspect_TOT_SOLID, // theType
96 (Quantity_NameOfColor)(aColor++), // theColor
97 Font_FA_BoldItalic, // theFontAspect
101 Graphic3d_VTA_BOTTOM,
102 Standard_False); // aIsZoomable
104 myAISContext->Display(aText, Standard_False);
109 TCollection_AsciiString Text("font 2 scale ");Text+=j/10.0;
110 Handle (Sample2D_Text) aText =
111 new Sample2D_Text(Text,
112 gp_Pnt(140.0,15.0*(j-5.0),0.0), // thePosition
113 Aspect_TOT_SOLID, // theType
115 (Quantity_NameOfColor)(aColor++), // theColor
116 Font_FA_Bold, // theFontAspect
120 Graphic3d_VTA_BOTTOM,
121 Standard_False); // aIsZoomable
122 myAISContext->Display(aText,Standard_False);
126 TCollection_AsciiString Text("font 3 scale ");Text+=j/10.0;
127 Handle (Sample2D_Text) aText =
128 new Sample2D_Text(Text,
129 gp_Pnt(200.0,15.0*(j-10.0),0.0), // thePosition
130 Aspect_TOT_SOLID, // theType
132 (Quantity_NameOfColor)(aColor++),// theColor
133 Font_FA_Italic, // theFontAspect
134 "Georgia", // theFont
137 Graphic3d_VTA_BOTTOM,
138 Standard_False); // aIsZoomable
139 myAISContext->Display(aText,Standard_False);
142 FitAll2DViews(Standard_True); // Update Viewer
146 void CViewer2dDoc::OnBUTTONTestMarkers()
149 Standard_Integer aColor = 20;
150 for (int i=1;i<=2;i++)
152 Handle (Sample2D_Markers) aMarker =
153 new Sample2D_Markers(10+5,5*i,Aspect_TOM_POINT,Quantity_NOC_YELLOW,2.0);
154 myAISContext->Display(aMarker, Standard_False);
156 for (int i=1;i<=2;i++)
158 Handle (Sample2D_Markers) aMarker =
159 new Sample2D_Markers(10+10,5*i,Aspect_TOM_O,(Quantity_NameOfColor)(aColor++));
160 myAISContext->Display(aMarker, Standard_False);
162 for (int i=1;i<=2;i++)
164 Handle (Sample2D_Markers) aMarker =
165 new Sample2D_Markers(10+15,5*i,Aspect_TOM_O_PLUS,(Quantity_NameOfColor)(aColor++));
166 myAISContext->Display(aMarker, Standard_False);
168 for (int i=1;i<=2;i++)
170 Handle (Sample2D_Markers) aMarker =
171 new Sample2D_Markers(10+20,5*i,Aspect_TOM_RING1,(Quantity_NameOfColor)(aColor++));
172 myAISContext->Display(aMarker, Standard_False);
174 for (int i=1;i<=2;i++)
177 Handle (Sample2D_Markers) aMarker =
178 new Sample2D_Markers(10+25,5*i,Aspect_TOM_STAR,(Quantity_NameOfColor)(aColor++));
179 myAISContext->Display(aMarker, Standard_False);
181 for (int i=1;i<=2;i++)
183 Handle (Sample2D_Markers) aMarker =
184 new Sample2D_Markers(10+30,5*i,Aspect_TOM_O_X,(Quantity_NameOfColor)(aColor++));
185 myAISContext->Display(aMarker, Standard_False);
188 FitAll2DViews(Standard_False); // Update Viewer
190 void CViewer2dDoc::OnBUTTONTestLine()
192 for (int i=0;i<=13;++i)
193 for (int j=0;j<=5;++j)
195 //set of rectangles here
196 TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(gp_Pnt(10*i,10*j,0.), gp_Pnt(10*i+7,10*j,0.));
197 TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(gp_Pnt(10*i+7,10*j,0.), gp_Pnt(10*i+7,10*j+5,0.));
198 TopoDS_Edge E3 = BRepBuilderAPI_MakeEdge(gp_Pnt(10*i+7,10*j+5,0.), gp_Pnt(10*i,10*j+5,0.));
199 TopoDS_Edge E4 = BRepBuilderAPI_MakeEdge(gp_Pnt(10*i,10*j+5,0.), gp_Pnt(10*i,10*j,0.));
200 TopoDS_Wire W = BRepBuilderAPI_MakeWire(E1,E2,E3,E4);
201 TopoDS_Face F = BRepBuilderAPI_MakeFace(W);
202 Handle_AIS_Shape aRect = new AIS_Shape(F);
203 //set attributes of boundaries
204 Handle(AIS_Drawer) aDrawer = new AIS_Drawer();
205 Handle(Prs3d_LineAspect) aLineAttrib =
206 new Prs3d_LineAspect(Quantity_NOC_YELLOW,
207 (Aspect_TypeOfLine)(Aspect_TOL_SOLID+j),1);
208 aDrawer->SetFaceBoundaryAspect(aLineAttrib);
209 aDrawer->SetFaceBoundaryDraw(Standard_True);
210 aRect->SetAttributes(aDrawer);
212 myAISContext->SetDisplayMode(aRect,1);
213 myAISContext->SetColor(aRect,(Quantity_NameOfColor)(Quantity_NOC_CADETBLUE+2*i),Standard_False);
214 myAISContext->SetMaterial(aRect,Graphic3d_NOM_PLASTIC,Standard_False);
215 myAISContext->Display(aRect, Standard_False);
218 this->FitAll2DViews(Standard_True);
222 #include <AIS_Trihedron.hxx>
223 #include <Geom_Axis2Placement.hxx>
225 void CViewer2dDoc::OnBUTTONTestFace()
228 if(myAISContext->HasOpenedContext())
229 myAISContext->CloseAllContexts();
230 myAISContext->EraseAll();
232 CFileDialog dlg(TRUE,
235 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
236 "BRep Files (*.brep)|*.brep; ||",
239 CString initdir(((OCC_App*) AfxGetApp())->GetInitDataDir());
242 dlg.m_ofn.lpstrInitialDir = initdir;
244 if (dlg.DoModal() == IDOK)
246 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
247 CString filename = dlg.GetPathName();
248 Standard_CString aFileName = (Standard_CString)(LPCTSTR)filename;
250 TopoDS_Shape aFaceShape;
251 BRep_Builder aBuilder;
252 //Standard_Boolean result = BRepTools::Read(aFaceShape,aFileName,aBuilder);
253 BRepTools::Read(aFaceShape,aFileName,aBuilder);
255 if(aFaceShape.IsNull() || aFaceShape.ShapeType() != TopAbs_FACE)
257 AfxMessageBox("The shape must be not a null Face");
261 TopoDS_Face aFace = TopoDS::Face(aFaceShape);
262 Handle(Sample2D_Face) anAISFace = new Sample2D_Face(aFaceShape);
263 myAISContext->Display(anAISFace,Standard_True);
264 //activate selection mode for edges selection
265 myAISContext->OpenLocalContext();
266 myAISContext->Activate(anAISFace,2);
268 FitAll2DViews(Standard_False);
275 void CViewer2dDoc::OnBUTTONTestRect()
278 TopoDS_Edge E11 = BRepBuilderAPI_MakeEdge(gp_Pnt(40.,0.,0.), gp_Pnt(82.5,25.,0.));
279 TopoDS_Edge E12 = BRepBuilderAPI_MakeEdge(gp_Pnt(82.5,25.,0.), gp_Pnt(42.5,93.,0.));
280 TopoDS_Edge E13 = BRepBuilderAPI_MakeEdge(gp_Pnt(42.5,93.,0.), gp_Pnt(0.,68.,0.));
281 TopoDS_Edge E14 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.,68.,0.), gp_Pnt(40.,0.,0.));
282 TopoDS_Wire W1 = BRepBuilderAPI_MakeWire(E11,E12,E13,E14);
283 Handle_AIS_Shape aRect1 = new AIS_Shape(W1);
284 myAISContext->Display(aRect1);
285 myAISContext->SetColor(aRect1,Quantity_NOC_YELLOW);
288 TopoDS_Edge E21 = BRepBuilderAPI_MakeEdge(gp_Pnt(110.,0.,0.), gp_Pnt(152.5,25.,0.));
289 TopoDS_Edge E22 = BRepBuilderAPI_MakeEdge(gp_Pnt(152.5,25.,0.), gp_Pnt(112.5,93.,0.));
290 TopoDS_Edge E23 = BRepBuilderAPI_MakeEdge(gp_Pnt(112.5,93.,0.), gp_Pnt(70.,68.,0.));
291 TopoDS_Edge E24 = BRepBuilderAPI_MakeEdge(gp_Pnt(70.,68.,0.), gp_Pnt(110.,0.,0.));
292 TopoDS_Wire W2 = BRepBuilderAPI_MakeWire(E21,E22,E23,E24);
293 Handle_AIS_Shape aRect2 = new AIS_Shape(W2);
294 myAISContext->Display(aRect2);
295 myAISContext->SetColor(aRect2,Quantity_NOC_YELLOW);
296 myAISContext->SetSelectionMode(aRect2,2);
298 FitAll2DViews(Standard_True); // Update Viewer
301 void CViewer2dDoc::OnBUTTONTestCurve()
303 for(int i=0;i<=5;++i)
304 for(int j=0;j<=5;++j)
306 Handle(Geom_Point) aStart = new Geom_CartesianPoint(gp_Pnt(10*i,10*j,0.));
307 Handle(Geom_Point) anEnd = new Geom_CartesianPoint(gp_Pnt(10*i+5,10*j+10,0.));
308 Handle(AIS_Line) aLine = new AIS_Line(aStart,anEnd);
309 Handle(Prs3d_LineAspect) aLineAttrib =
310 new Prs3d_LineAspect((Quantity_NameOfColor)(Quantity_NOC_CADETBLUE+2*i+2*j),
311 (Aspect_TypeOfLine)((Aspect_TOL_DASH+i+j)%5),2+i+j);
312 aLine->Attributes()->SetLineAspect(aLineAttrib);
313 myAISContext->Display(aLine,Standard_False);
315 FitAll2DViews(Standard_True);
318 void CViewer2dDoc::OnBUTTONTestImage()
320 CFileDialog anOpenImageDlg (TRUE,
323 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
324 SupportedImageFormats() + "| all files (*.*)|*.*;||",
327 CString anInitDir (((OCC_App*) AfxGetApp())->GetInitDataDir());
328 anInitDir += "\\Data";
330 anOpenImageDlg.m_ofn.lpstrInitialDir = anInitDir;
331 if(anOpenImageDlg.DoModal() == IDOK)
333 SetCursor(AfxGetApp()->LoadStandardCursor (IDC_WAIT));
334 CString aFilePath = anOpenImageDlg.GetPathName();
335 TCollection_AsciiString aFileName (aFilePath);
338 if(myAISContext->HasOpenedContext())
339 myAISContext->CloseAllContexts();
340 myAISContext->EraseAll();
342 Handle(Sample2D_Image) anImage = new Sample2D_Image (aFileName);
343 anImage->SetCoord (40,50) ;
344 anImage->SetScale (1.0);
345 myAISContext->Display (anImage, Standard_False);
346 myAISContext->SetDisplayMode (anImage,3,Standard_False);
347 FitAll2DViews (Standard_True);
351 void CViewer2dDoc::OnBUTTONMultipleImage()
353 CFileDialog anOpenImageDlg (TRUE,
356 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
357 SupportedImageFormats() + "| all files (*.*)|*.*;||",
360 CString anInitDir (((OCC_App*) AfxGetApp())->GetInitDataDir());
361 anInitDir += "\\Data";
363 anOpenImageDlg.m_ofn.lpstrInitialDir = anInitDir;
365 if (anOpenImageDlg.DoModal() == IDOK)
367 SetCursor(AfxGetApp()->LoadStandardCursor (IDC_WAIT));
368 CString aFilePath = anOpenImageDlg.GetPathName();
369 TCollection_AsciiString aFileName (aFilePath);
372 if(myAISContext->HasOpenedContext())
373 myAISContext->CloseAllContexts();
374 myAISContext->EraseAll();
378 Handle(Sample2D_Image) anImage = new Sample2D_Image (aFileName);
379 anImage->SetCoord (40, 50);
380 anImage->SetScale (0.5);
381 myAISContext->Display (anImage, Standard_False);
382 myAISContext->SetDisplayMode (anImage, 3, Standard_False);
385 Handle(Sample2D_Image) anImage = new Sample2D_Image (aFileName);
386 anImage->SetCoord (100, 50);
387 anImage->SetScale (0.9);
388 myAISContext->Display (anImage, Standard_False);
389 myAISContext->SetDisplayMode (anImage, 3, Standard_False);
392 Handle(Sample2D_Image) anImage = new Sample2D_Image (aFileName);
393 anImage->SetCoord (40, 40);
394 anImage->SetScale (0.3);
395 myAISContext->Display (anImage, Standard_False);
396 myAISContext->SetDisplayMode (anImage, 3, Standard_False);
399 Handle(Sample2D_Image) anImage = new Sample2D_Image (aFileName);
400 anImage->SetCoord (50, 40);
401 myAISContext->Display (anImage, Standard_False);
402 myAISContext->SetDisplayMode (anImage, 3, Standard_False);
405 Handle(Sample2D_Image) anImage = new Sample2D_Image (aFileName);
406 anImage->SetCoord (80, 45);
407 anImage->SetScale (2);
408 myAISContext->Display (anImage, Standard_False);
409 myAISContext->SetDisplayMode (anImage, 3, Standard_False);
412 Handle(Sample2D_Image) anImage = new Sample2D_Image (aFileName);
413 anImage->SetCoord (20, -20);
414 myAISContext->Display (anImage, Standard_False);
415 myAISContext->SetDisplayMode (anImage, 3, Standard_False);
418 Handle(Sample2D_Image) anImage = new Sample2D_Image (aFileName);
419 anImage->SetCoord (0, 0);
420 anImage->SetScale (0.5);
421 myAISContext->Display (anImage, Standard_False);
422 myAISContext->SetDisplayMode (anImage, 3, Standard_False);
424 FitAll2DViews (Standard_True); // Update Viewer