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 10.0*M_PI, // theAngle
76 (Quantity_NameOfColor)(aColor++), // theColor
77 Font_FA_Regular, // theFontAspect
82 Standard_False); // aIsZoomable
84 myAISContext->Display(aText, Standard_False);
89 TCollection_AsciiString Text("font 1 scale ");Text+=j/10.0;
90 Handle (Sample2D_Text) aText =
91 new Sample2D_Text(Text,
92 gp_Pnt(80.,15.0*(j-10.0),0.0), // thePosition
94 (Quantity_NameOfColor)(aColor++), // theColor
95 Font_FA_BoldItalic, // theFontAspect
100 Standard_False); // aIsZoomable
102 myAISContext->Display(aText, Standard_False);
107 TCollection_AsciiString Text("font 2 scale ");Text+=j/10.0;
108 Handle (Sample2D_Text) aText =
109 new Sample2D_Text(Text,
110 gp_Pnt(140.0,15.0*(j-5.0),0.0), // thePosition
112 (Quantity_NameOfColor)(aColor++), // theColor
113 Font_FA_Bold, // theFontAspect
117 Graphic3d_VTA_BOTTOM,
118 Standard_False); // aIsZoomable
119 myAISContext->Display(aText,Standard_False);
123 TCollection_AsciiString Text("font 3 scale ");Text+=j/10.0;
124 Handle (Sample2D_Text) aText =
125 new Sample2D_Text(Text,
126 gp_Pnt(200.0,15.0*(j-10.0),0.0), // thePosition
128 (Quantity_NameOfColor)(aColor++),// theColor
129 Font_FA_Italic, // theFontAspect
130 "Georgia", // theFont
133 Graphic3d_VTA_BOTTOM,
134 Standard_False); // aIsZoomable
135 myAISContext->Display(aText,Standard_False);
138 FitAll2DViews(Standard_True); // Update Viewer
142 void CViewer2dDoc::OnBUTTONTestMarkers()
145 Standard_Integer aColor = 20;
146 for (int i=1;i<=2;i++)
148 Handle (Sample2D_Markers) aMarker =
149 new Sample2D_Markers(10+5,5*i,Aspect_TOM_POINT,Quantity_NOC_YELLOW,2.0);
150 myAISContext->Display(aMarker, Standard_False);
152 for (int i=1;i<=2;i++)
154 Handle (Sample2D_Markers) aMarker =
155 new Sample2D_Markers(10+10,5*i,Aspect_TOM_O,(Quantity_NameOfColor)(aColor++));
156 myAISContext->Display(aMarker, Standard_False);
158 for (int i=1;i<=2;i++)
160 Handle (Sample2D_Markers) aMarker =
161 new Sample2D_Markers(10+15,5*i,Aspect_TOM_O_PLUS,(Quantity_NameOfColor)(aColor++));
162 myAISContext->Display(aMarker, Standard_False);
164 for (int i=1;i<=2;i++)
166 Handle (Sample2D_Markers) aMarker =
167 new Sample2D_Markers(10+20,5*i,Aspect_TOM_RING1,(Quantity_NameOfColor)(aColor++));
168 myAISContext->Display(aMarker, Standard_False);
170 for (int i=1;i<=2;i++)
173 Handle (Sample2D_Markers) aMarker =
174 new Sample2D_Markers(10+25,5*i,Aspect_TOM_STAR,(Quantity_NameOfColor)(aColor++));
175 myAISContext->Display(aMarker, Standard_False);
177 for (int i=1;i<=2;i++)
179 Handle (Sample2D_Markers) aMarker =
180 new Sample2D_Markers(10+30,5*i,Aspect_TOM_O_X,(Quantity_NameOfColor)(aColor++));
181 myAISContext->Display(aMarker, Standard_False);
184 FitAll2DViews(Standard_False); // Update Viewer
186 void CViewer2dDoc::OnBUTTONTestLine()
188 for (int i=0;i<=13;++i)
189 for (int j=0;j<=5;++j)
191 //set of rectangles here
192 TopoDS_Edge E1 = BRepBuilderAPI_MakeEdge(gp_Pnt(10*i,10*j,0.), gp_Pnt(10*i+7,10*j,0.));
193 TopoDS_Edge E2 = BRepBuilderAPI_MakeEdge(gp_Pnt(10*i+7,10*j,0.), gp_Pnt(10*i+7,10*j+5,0.));
194 TopoDS_Edge E3 = BRepBuilderAPI_MakeEdge(gp_Pnt(10*i+7,10*j+5,0.), gp_Pnt(10*i,10*j+5,0.));
195 TopoDS_Edge E4 = BRepBuilderAPI_MakeEdge(gp_Pnt(10*i,10*j+5,0.), gp_Pnt(10*i,10*j,0.));
196 TopoDS_Wire W = BRepBuilderAPI_MakeWire(E1,E2,E3,E4);
197 TopoDS_Face F = BRepBuilderAPI_MakeFace(W);
198 Handle_AIS_Shape aRect = new AIS_Shape(F);
199 //set attributes of boundaries
200 Handle(Prs3d_Drawer) aDrawer = new Prs3d_Drawer();
201 Handle(Prs3d_LineAspect) aLineAttrib =
202 new Prs3d_LineAspect(Quantity_NOC_YELLOW,
203 (Aspect_TypeOfLine)(Aspect_TOL_SOLID+j),1);
204 aDrawer->SetFaceBoundaryAspect(aLineAttrib);
205 aDrawer->SetFaceBoundaryDraw(Standard_True);
206 aRect->SetAttributes(aDrawer);
208 myAISContext->SetDisplayMode(aRect,1);
209 myAISContext->SetColor(aRect,(Quantity_NameOfColor)(Quantity_NOC_CADETBLUE+2*i),Standard_False);
210 myAISContext->SetMaterial(aRect,Graphic3d_NOM_PLASTIC,Standard_False);
211 myAISContext->Display(aRect, Standard_False);
214 this->FitAll2DViews(Standard_True);
218 #include <AIS_Trihedron.hxx>
219 #include <Geom_Axis2Placement.hxx>
221 void CViewer2dDoc::OnBUTTONTestFace()
224 if(myAISContext->HasOpenedContext())
225 myAISContext->CloseAllContexts();
226 myAISContext->EraseAll();
228 CFileDialog dlg(TRUE,
231 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
232 L"BRep Files (*.brep)|*.brep; ||",
235 CString initdir(((OCC_App*) AfxGetApp())->GetInitDataDir());
238 dlg.m_ofn.lpstrInitialDir = initdir;
240 if (dlg.DoModal() == IDOK)
242 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
244 std::filebuf aFileBuf;
245 std::istream aStream (&aFileBuf);
246 if (!aFileBuf.open (dlg.GetPathName(), ios::in))
248 AfxMessageBox (L"The shape must be not a null Face");
252 TopoDS_Shape aFaceShape;
253 BRep_Builder aBuilder;
254 BRepTools::Read (aFaceShape, aStream, aBuilder);
255 if(aFaceShape.IsNull() || aFaceShape.ShapeType() != TopAbs_FACE)
257 AfxMessageBox (L"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->Activate(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_ExtendedString aFileNameW ((Standard_ExtString )(const wchar_t* )aFilePath);
336 TCollection_AsciiString aFileName (aFileNameW, '?');
339 if(myAISContext->HasOpenedContext())
340 myAISContext->CloseAllContexts();
341 myAISContext->EraseAll();
343 Handle(Sample2D_Image) anImage = new Sample2D_Image (aFileName);
344 anImage->SetCoord (40,50) ;
345 anImage->SetScale (1.0);
346 myAISContext->Display (anImage, Standard_False);
347 myAISContext->SetDisplayMode (anImage,3,Standard_False);
348 FitAll2DViews (Standard_True);
352 void CViewer2dDoc::OnBUTTONMultipleImage()
354 CFileDialog anOpenImageDlg (TRUE,
357 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
358 SupportedImageFormats() + "| all files (*.*)|*.*;||",
361 CString anInitDir (((OCC_App*) AfxGetApp())->GetInitDataDir());
362 anInitDir += "\\Data";
364 anOpenImageDlg.m_ofn.lpstrInitialDir = anInitDir;
366 if (anOpenImageDlg.DoModal() == IDOK)
368 SetCursor(AfxGetApp()->LoadStandardCursor (IDC_WAIT));
369 CString aFilePath = anOpenImageDlg.GetPathName();
370 TCollection_ExtendedString aFileNameW ((Standard_ExtString )(const wchar_t* )aFilePath);
371 TCollection_AsciiString aFileName (aFileNameW, '?');
374 if(myAISContext->HasOpenedContext())
375 myAISContext->CloseAllContexts();
376 myAISContext->EraseAll();
380 Handle(Sample2D_Image) anImage = new Sample2D_Image (aFileName);
381 anImage->SetCoord (40, 50);
382 anImage->SetScale (0.5);
383 myAISContext->Display (anImage, Standard_False);
384 myAISContext->SetDisplayMode (anImage, 3, Standard_False);
387 Handle(Sample2D_Image) anImage = new Sample2D_Image (aFileName);
388 anImage->SetCoord (100, 50);
389 anImage->SetScale (0.9);
390 myAISContext->Display (anImage, Standard_False);
391 myAISContext->SetDisplayMode (anImage, 3, Standard_False);
394 Handle(Sample2D_Image) anImage = new Sample2D_Image (aFileName);
395 anImage->SetCoord (40, 40);
396 anImage->SetScale (0.3);
397 myAISContext->Display (anImage, Standard_False);
398 myAISContext->SetDisplayMode (anImage, 3, Standard_False);
401 Handle(Sample2D_Image) anImage = new Sample2D_Image (aFileName);
402 anImage->SetCoord (50, 40);
403 myAISContext->Display (anImage, Standard_False);
404 myAISContext->SetDisplayMode (anImage, 3, Standard_False);
407 Handle(Sample2D_Image) anImage = new Sample2D_Image (aFileName);
408 anImage->SetCoord (80, 45);
409 anImage->SetScale (2);
410 myAISContext->Display (anImage, Standard_False);
411 myAISContext->SetDisplayMode (anImage, 3, Standard_False);
414 Handle(Sample2D_Image) anImage = new Sample2D_Image (aFileName);
415 anImage->SetCoord (20, -20);
416 myAISContext->Display (anImage, Standard_False);
417 myAISContext->SetDisplayMode (anImage, 3, Standard_False);
420 Handle(Sample2D_Image) anImage = new Sample2D_Image (aFileName);
421 anImage->SetCoord (0, 0);
422 anImage->SetScale (0.5);
423 myAISContext->Display (anImage, Standard_False);
424 myAISContext->SetDisplayMode (anImage, 3, Standard_False);
426 FitAll2DViews (Standard_True); // Update Viewer