1 // GeometryDoc.cpp : implementation of the CGeometryDoc class
6 #include "GeometryDoc.h"
7 #include "GeoAlgo_Sol.hxx"
8 #include "GeometryApp.h"
9 #include "GeometryView2D.h"
10 #include "GeometryView.h"
14 static char THIS_FILE[] = __FILE__;
16 #include "GeomSources.h"
24 #define WAIT_A_LITTLE WaitForInput(500)
26 #define MAX_PARAM 1000 // if a surface parameter is infinite, it is assingned
27 // this value in order to display the "infinit" object in the viewer.
29 /////////////////////////////////////////////////////////////////////////////
32 IMPLEMENT_DYNCREATE(CGeometryDoc, CDocument)
34 BEGIN_MESSAGE_MAP(CGeometryDoc, CDocument)
35 //{{AFX_MSG_MAP(CGeometryDoc)
36 ON_COMMAND(ID_WINDOW_NEW2D, OnWindowNew2d)
37 ON_COMMAND(ID_BUTTON_Test_1, OnBUTTONTest1)
38 ON_COMMAND(ID_BUTTON_Test_2, OnBUTTONTest2)
39 ON_COMMAND(ID_BUTTON_Test_3, OnBUTTONTest3)
40 ON_COMMAND(ID_BUTTON_Test_4, OnBUTTONTest4)
41 ON_COMMAND(ID_BUTTON_Test_5, OnBUTTONTest5)
42 ON_COMMAND(ID_BUTTON_Test_6, OnBUTTONTest6)
43 ON_COMMAND(ID_BUTTON_Test_7, OnBUTTONTest7)
44 ON_COMMAND(ID_BUTTON_Test_8, OnBUTTONTest8)
45 ON_COMMAND(ID_BUTTON_Test_9, OnBUTTONTest9)
46 ON_COMMAND(ID_BUTTON_Test_23, OnBUTTONTest23)
47 ON_COMMAND(ID_BUTTON_Test_22, OnBUTTONTest22)
48 ON_COMMAND(ID_BUTTON_Test_10, OnBUTTONTest10)
49 ON_COMMAND(ID_BUTTON_Test_11, OnBUTTONTest11)
50 ON_COMMAND(ID_BUTTON_Test_12, OnBUTTONTest12)
51 ON_COMMAND(ID_BUTTON_Test_13, OnBUTTONTest13)
52 ON_COMMAND(ID_BUTTON_Test_14, OnBUTTONTest14)
53 ON_COMMAND(ID_BUTTON_Test_15, OnBUTTONTest15)
54 ON_COMMAND(ID_BUTTON_Test_16, OnBUTTONTest16)
55 ON_COMMAND(ID_BUTTON_Test_17, OnBUTTONTest17)
56 ON_COMMAND(ID_BUTTON_Test_18, OnBUTTONTest18)
57 ON_COMMAND(ID_BUTTON_Test_19, OnBUTTONTest19)
58 ON_COMMAND(ID_BUTTON_Test_20, OnBUTTONTest20)
59 ON_COMMAND(ID_BUTTON_Test_21, OnBUTTONTest21)
60 ON_COMMAND(ID_BUTTON_Test_24, OnBUTTONTest24)
61 ON_COMMAND(ID_BUTTON_Test_25, OnBUTTONTest25)
62 ON_COMMAND(ID_BUTTON_Test_26, OnBUTTONTest26)
63 ON_COMMAND(ID_BUTTON_Test_27, OnBUTTONTest27)
64 ON_COMMAND(ID_BUTTON_Test_28, OnBUTTONTest28)
65 ON_COMMAND(ID_BUTTON_Test_29, OnBUTTONTest29)
66 ON_COMMAND(ID_BUTTON_Test_30, OnBUTTONTest30)
67 ON_COMMAND(ID_BUTTON_Test_31, OnBUTTONTest31)
68 ON_COMMAND(ID_BUTTON_Test_32, OnBUTTONTest32)
69 ON_COMMAND(ID_BUTTON_Test_33, OnBUTTONTest33)
70 ON_COMMAND(ID_BUTTON_Test_34, OnBUTTONTest34)
71 ON_COMMAND(ID_BUTTON_Test_35, OnBUTTONTest35)
72 ON_COMMAND(ID_BUTTON_Test_36, OnBUTTONTest36)
73 ON_COMMAND(ID_BUTTON_Test_37, OnBUTTONTest37)
74 ON_COMMAND(ID_BUTTON_Test_38, OnBUTTONTest38)
75 ON_COMMAND(ID_BUTTON_Test_39, OnBUTTONTest39)
76 ON_COMMAND(ID_BUTTON_Test_40, OnBUTTONTest40)
77 ON_COMMAND(ID_BUTTON_Test_41, OnBUTTONTest41)
78 ON_COMMAND(ID_BUTTON_Test_42, OnBUTTONTest42)
79 ON_COMMAND(ID_BUTTON_Test_43, OnBUTTONTest43)
80 ON_COMMAND(ID_BUTTON_Test_44, OnBUTTONTest44)
81 ON_COMMAND(ID_BUTTON_Test_45, OnBUTTONTest45)
82 ON_COMMAND(ID_BUTTON_Test_46, OnBUTTONTest46)
83 ON_COMMAND(ID_BUTTON_Test_47, OnBUTTONTest47)
84 ON_COMMAND(ID_BUTTON_Test_48, OnBUTTONTest48)
85 ON_COMMAND(ID_BUTTON_Test_49, OnBUTTONTest49)
86 ON_COMMAND(ID_BUTTON_Test_50, OnBUTTONTest50)
87 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_1 , OnUpdateBUTTONTest1 )
88 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_2 , OnUpdateBUTTONTest2 )
89 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_3 , OnUpdateBUTTONTest3 )
90 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_4 , OnUpdateBUTTONTest4 )
91 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_5 , OnUpdateBUTTONTest5 )
92 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_6 , OnUpdateBUTTONTest6 )
93 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_7 , OnUpdateBUTTONTest7 )
94 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_8 , OnUpdateBUTTONTest8 )
95 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_9 , OnUpdateBUTTONTest9 )
96 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_10 , OnUpdateBUTTONTest10 )
97 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_11 , OnUpdateBUTTONTest11 )
98 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_12 , OnUpdateBUTTONTest12 )
99 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_13 , OnUpdateBUTTONTest13 )
100 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_14 , OnUpdateBUTTONTest14 )
101 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_15 , OnUpdateBUTTONTest15 )
102 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_16 , OnUpdateBUTTONTest16 )
103 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_17 , OnUpdateBUTTONTest17 )
104 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_18 , OnUpdateBUTTONTest18 )
105 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_19 , OnUpdateBUTTONTest19 )
106 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_20 , OnUpdateBUTTONTest20 )
107 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_21 , OnUpdateBUTTONTest21 )
108 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_22 , OnUpdateBUTTONTest22 )
109 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_23 , OnUpdateBUTTONTest23 )
110 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_24 , OnUpdateBUTTONTest24 )
111 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_25 , OnUpdateBUTTONTest25 )
112 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_26 , OnUpdateBUTTONTest26 )
113 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_27 , OnUpdateBUTTONTest27 )
114 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_28 , OnUpdateBUTTONTest28 )
115 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_29 , OnUpdateBUTTONTest29 )
116 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_30 , OnUpdateBUTTONTest30 )
117 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_31 , OnUpdateBUTTONTest31 )
118 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_32 , OnUpdateBUTTONTest32 )
119 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_33 , OnUpdateBUTTONTest33 )
120 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_34 , OnUpdateBUTTONTest34 )
121 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_35 , OnUpdateBUTTONTest35 )
122 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_36 , OnUpdateBUTTONTest36 )
123 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_37 , OnUpdateBUTTONTest37 )
124 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_38 , OnUpdateBUTTONTest38 )
125 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_39 , OnUpdateBUTTONTest39 )
126 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_40 , OnUpdateBUTTONTest40 )
127 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_41 , OnUpdateBUTTONTest41 )
128 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_42 , OnUpdateBUTTONTest42 )
129 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_43 , OnUpdateBUTTONTest43 )
130 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_44 , OnUpdateBUTTONTest44 )
131 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_45 , OnUpdateBUTTONTest45 )
132 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_46 , OnUpdateBUTTONTest46 )
133 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_47 , OnUpdateBUTTONTest47 )
134 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_48 , OnUpdateBUTTONTest48 )
135 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_49 , OnUpdateBUTTONTest49 )
136 ON_UPDATE_COMMAND_UI(ID_BUTTON_Test_50 , OnUpdateBUTTONTest50 )
137 ON_COMMAND(ID_Create_Sol, OnCreateSol)
138 ON_COMMAND(ID_BUTTON_Simplify, OnSimplify)
142 /////////////////////////////////////////////////////////////////////////////
143 // CGeometryDoc construction/destruction
145 CGeometryDoc::CGeometryDoc()
151 // TODO: add one-time construction code here
152 Handle(Graphic3d_WNTGraphicDevice) theGraphicDevice =
153 ((CGeometryApp*)AfxGetApp())->GetGraphicDevice();
155 TCollection_ExtendedString a3DName("Visu3D");
156 myViewer = new V3d_Viewer(theGraphicDevice,a3DName.ToExtString());
157 myViewer->SetDefaultLights();
158 myViewer->SetLightOn();
160 myAISContext =new AIS_InteractiveContext(myViewer);
161 myAISContext->DefaultDrawer()->UIsoAspect()->SetNumber(11);
162 myAISContext->DefaultDrawer()->VIsoAspect()->SetNumber(11);
164 TCollection_ExtendedString a2DName("Visu2D");
165 myViewer2D = new V2d_Viewer(theGraphicDevice,a2DName.ToExtString());
166 myViewer2D->SetCircularGridValues(0,0,1,8,0);
167 myViewer2D->SetRectangularGridValues(0,0,1,1,0);
168 myISessionContext= new ISession2D_InteractiveContext(myViewer2D);
169 myCResultDialog.Create(CResultDialog::IDD,NULL);
172 myCResultDialog.GetWindowRect(&dlgrect);
173 LONG width = dlgrect.right-dlgrect.left;
174 LONG height = dlgrect.bottom-dlgrect.top;
176 AfxGetApp()->m_pMainWnd->GetWindowRect(&MainWndRect);
177 LONG left = MainWndRect.left+3;
178 LONG top = MainWndRect.top + 138;
179 myCResultDialog.MoveWindow(left,top,width,height);
181 ((CGeometryApp*)AfxGetApp())->CreateView2D(this);
186 CGeometryDoc::~CGeometryDoc()
190 BOOL CGeometryDoc::OnNewDocument()
192 if (!CDocument::OnNewDocument())
195 // TODO: add reinitialization code here
196 // (SDI documents will reuse this document)
197 // compute a graphic device --> the same for all Views
204 void CGeometryDoc::OnWindowNew2d()
207 ((CGeometryApp*)AfxGetApp())->CreateView2D(this);
210 /////////////////////////////////////////////////////////////////////////////
211 // CGeometryDoc serialization
213 void CGeometryDoc::Serialize(CArchive& ar)
217 // TODO: add storing code here
221 // TODO: add loading code here
225 /////////////////////////////////////////////////////////////////////////////
226 // CGeometryDoc diagnostics
229 void CGeometryDoc::AssertValid() const
231 CDocument::AssertValid();
234 void CGeometryDoc::Dump(CDumpContext& dc) const
240 /////////////////////////////////////////////////////////////////////////////
241 // CGeometryDoc commands
243 //-----------------------------------------------------------------------------------------
245 //-----------------------------------------------------------------------------------------
246 void CGeometryDoc::DragEvent2D(const Standard_Integer x ,
247 const Standard_Integer y ,
248 const Standard_Integer TheState ,
249 const Handle(V2d_View)& aView )
254 //-----------------------------------------------------------------------------------------
256 //-----------------------------------------------------------------------------------------
257 void CGeometryDoc::InputEvent2D(const Standard_Integer x ,
258 const Standard_Integer y ,
259 const Handle(V2d_View)& aView )
261 myISessionContext->Pick(aView,x,y);
264 //-----------------------------------------------------------------------------------------
266 //-----------------------------------------------------------------------------------------
267 void CGeometryDoc::MoveEvent2D(const Standard_Integer x ,
268 const Standard_Integer y ,
269 const Handle(V2d_View)& aView )
271 myISessionContext->Move(aView,x,y);
274 //-----------------------------------------------------------------------------------------
276 //-----------------------------------------------------------------------------------------
277 void CGeometryDoc::ShiftMoveEvent2D(const Standard_Integer x ,
278 const Standard_Integer y ,
279 const Handle(V2d_View)& aView )
283 //-----------------------------------------------------------------------------------------
285 //-----------------------------------------------------------------------------------------
286 void CGeometryDoc::ShiftDragEvent2D(const Standard_Integer x ,
287 const Standard_Integer y ,
288 const Standard_Integer TheState ,
289 const Handle(V2d_View)& aView )
294 //-----------------------------------------------------------------------------------------
296 //-----------------------------------------------------------------------------------------
297 void CGeometryDoc::ShiftInputEvent2D(const Standard_Integer x ,
298 const Standard_Integer y ,
299 const Handle(V2d_View)& aView )
303 //-----------------------------------------------------------------------------------------
305 //-----------------------------------------------------------------------------------------
306 void CGeometryDoc::Popup2D(const Standard_Integer x,
307 const Standard_Integer y ,
308 const Handle(V2d_View)& aView )
312 VERIFY(menu.LoadMenu(IDR_Popup3D));
315 pPopup = menu.GetSubMenu(0);
317 ASSERT(pPopup != NULL);
319 POINT winCoord = { x , y };
320 Handle(WNT_Window) aWNTWindow=
321 Handle(WNT_Window)::DownCast(aView->Driver()->Window());
322 ClientToScreen ( (HWND)(aWNTWindow->HWindow()),&winCoord);
323 pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON , winCoord.x, winCoord.y ,
328 void CGeometryDoc::Put2DOnTop(bool isMax)
330 POSITION position = GetFirstViewPosition();
331 while (position != (POSITION)NULL)
333 CView* pCurrentView = (CView*)GetNextView(position);
334 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView2D ) ) )
336 ASSERT_VALID(pCurrentView);
337 CFrameWnd* pParentFrm = pCurrentView->GetParentFrame();
338 ASSERT(pParentFrm != (CFrameWnd *)NULL);
339 // simply make the frame window visible
341 pParentFrm->ActivateFrame(SW_SHOWMAXIMIZED);
343 pParentFrm->ActivateFrame(SW_SHOW);
349 void CGeometryDoc::Minimize2D()
351 POSITION position = GetFirstViewPosition();
352 while (position != (POSITION)NULL)
354 CView* pCurrentView = (CView*)GetNextView(position);
355 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView2D ) ) )
357 ASSERT_VALID(pCurrentView);
358 CFrameWnd* pParentFrm = pCurrentView->GetParentFrame();
359 ASSERT(pParentFrm != (CFrameWnd *)NULL);
360 // simply make the frame window visible
361 pParentFrm->ActivateFrame(SW_HIDE);
367 void CGeometryDoc::Fit2DViews()
369 POSITION position = GetFirstViewPosition();
370 while (position != (POSITION)NULL)
372 CView* pCurrentView = (CView*)GetNextView(position);
373 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView2D ) ) )
375 ASSERT_VALID(pCurrentView);
376 CGeometryView2D* aCGeometryView2D = (CGeometryView2D*)pCurrentView;
377 aCGeometryView2D->FitAll();
382 void CGeometryDoc::Put3DOnTop(bool isMax)
384 POSITION position = GetFirstViewPosition();
385 while (position != (POSITION)NULL)
387 CView* pCurrentView = (CView*)GetNextView(position);
388 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView ) ) )
390 ASSERT_VALID(pCurrentView);
391 CFrameWnd* pParentFrm = pCurrentView->GetParentFrame();
392 ASSERT(pParentFrm != (CFrameWnd *)NULL);
393 // simply make the frame window visible
395 pParentFrm->ActivateFrame(SW_SHOWMAXIMIZED);
397 pParentFrm->ActivateFrame(SW_SHOW);
402 void CGeometryDoc::Minimize3D()
404 POSITION position = GetFirstViewPosition();
405 while (position != (POSITION)NULL)
407 CView* pCurrentView = (CView*)GetNextView(position);
408 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView ) ) )
410 ASSERT_VALID(pCurrentView);
411 CFrameWnd* pParentFrm = pCurrentView->GetParentFrame();
412 ASSERT(pParentFrm != (CFrameWnd *)NULL);
413 // simply make the frame window visible
414 pParentFrm->ActivateFrame(SW_HIDE);
421 void CGeometryDoc::Fit3DViews(Quantity_Coefficient Coef)
423 POSITION position = GetFirstViewPosition();
424 while (position != (POSITION)NULL)
426 CView* pCurrentView = (CView*)GetNextView(position);
427 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView ) ) )
429 ASSERT_VALID(pCurrentView);
430 CGeometryView* aCGeometryView = (CGeometryView*)pCurrentView;
431 aCGeometryView->FitAll(Coef);
436 void CGeometryDoc::Set3DViewsZoom(const Quantity_Factor& Coef )
438 POSITION position = GetFirstViewPosition();
439 while (position != (POSITION)NULL)
441 CView* pCurrentView = (CView*)GetNextView(position);
442 if(pCurrentView->IsKindOf( RUNTIME_CLASS( CGeometryView ) ) )
444 ASSERT_VALID(pCurrentView);
445 CGeometryView* aCGeometryView = (CGeometryView*)pCurrentView;
446 aCGeometryView->SetZoom( Coef );
452 void CGeometryDoc::OnBUTTONTest1()
454 GeomSources::gpTest1(this); }
455 void CGeometryDoc::OnBUTTONTest2()
457 GeomSources::gpTest2(this); }
458 void CGeometryDoc::OnBUTTONTest3()
460 GeomSources::gpTest3(this); }
461 void CGeometryDoc::OnBUTTONTest4()
463 GeomSources::gpTest4(this); }
464 void CGeometryDoc::OnBUTTONTest5()
466 GeomSources::gpTest5(this); }
467 void CGeometryDoc::OnBUTTONTest6()
469 GeomSources::gpTest6(this); }
470 void CGeometryDoc::OnBUTTONTest7()
472 GeomSources::gpTest7(this); }
473 void CGeometryDoc::OnBUTTONTest8()
475 GeomSources::gpTest8(this); }
476 void CGeometryDoc::OnBUTTONTest9()
478 GeomSources::gpTest9(this); }
479 void CGeometryDoc::OnBUTTONTest10()
481 GeomSources::gpTest10(this); }
482 void CGeometryDoc::OnBUTTONTest11()
484 GeomSources::gpTest11(this); }
485 void CGeometryDoc::OnBUTTONTest12()
487 GeomSources::gpTest12(this); }
488 void CGeometryDoc::OnBUTTONTest13()
490 GeomSources::gpTest13(this); }
491 void CGeometryDoc::OnBUTTONTest14()
493 GeomSources::gpTest14(this); }
494 void CGeometryDoc::OnBUTTONTest15()
496 GeomSources::gpTest15(this); }
497 void CGeometryDoc::OnBUTTONTest16()
499 GeomSources::gpTest16(this); }
500 void CGeometryDoc::OnBUTTONTest17()
502 GeomSources::gpTest17(this); }
503 void CGeometryDoc::OnBUTTONTest18()
505 GeomSources::gpTest18(this); }
506 void CGeometryDoc::OnBUTTONTest19()
508 GeomSources::gpTest19(this); }
509 void CGeometryDoc::OnBUTTONTest20()
511 GeomSources::gpTest20(this); }
512 void CGeometryDoc::OnBUTTONTest21()
514 GeomSources::gpTest21(this); }
515 void CGeometryDoc::OnBUTTONTest22()
517 GeomSources::gpTest22(this); }
518 void CGeometryDoc::OnBUTTONTest23()
520 GeomSources::gpTest23(this); }
521 void CGeometryDoc::OnBUTTONTest24()
523 GeomSources::gpTest24(this); }
524 void CGeometryDoc::OnBUTTONTest25()
526 GeomSources::gpTest25(this); }
527 void CGeometryDoc::OnBUTTONTest26()
529 GeomSources::gpTest26(this); }
530 void CGeometryDoc::OnBUTTONTest27()
532 GeomSources::gpTest27(this); }
533 void CGeometryDoc::OnBUTTONTest28()
535 GeomSources::gpTest28(this); }
536 void CGeometryDoc::OnBUTTONTest29()
538 GeomSources::gpTest29(this); }
539 void CGeometryDoc::OnBUTTONTest30()
541 GeomSources::gpTest30(this); }
542 void CGeometryDoc::OnBUTTONTest31()
544 GeomSources::gpTest31(this); }
545 void CGeometryDoc::OnBUTTONTest32()
547 GeomSources::gpTest32(this); }
548 void CGeometryDoc::OnBUTTONTest33()
550 GeomSources::gpTest33(this); }
551 void CGeometryDoc::OnBUTTONTest34()
553 GeomSources::gpTest34(this); }
554 void CGeometryDoc::OnBUTTONTest35()
556 GeomSources::gpTest35(this); }
557 void CGeometryDoc::OnBUTTONTest36()
559 GeomSources::gpTest36(this); }
561 void CGeometryDoc::OnBUTTONTest37()
563 GeomSources::gpTest37(this); }
564 void CGeometryDoc::OnBUTTONTest38()
566 GeomSources::gpTest38(this); }
567 void CGeometryDoc::OnBUTTONTest39()
569 GeomSources::gpTest39(this); }
570 void CGeometryDoc::OnBUTTONTest40()
572 GeomSources::gpTest40(this); }
573 void CGeometryDoc::OnBUTTONTest41()
575 GeomSources::gpTest41(this); }
576 void CGeometryDoc::OnBUTTONTest42()
578 GeomSources::gpTest42(this); }
579 void CGeometryDoc::OnBUTTONTest43()
581 GeomSources::gpTest43(this); }
582 void CGeometryDoc::OnBUTTONTest44()
584 GeomSources::gpTest44(this); }
585 void CGeometryDoc::OnBUTTONTest45()
587 GeomSources::gpTest45(this); }
588 void CGeometryDoc::OnBUTTONTest46()
590 GeomSources::gpTest46(this); }
591 void CGeometryDoc::OnBUTTONTest47()
593 GeomSources::gpTest47(this); }
594 void CGeometryDoc::OnBUTTONTest48()
596 GeomSources::gpTest48(this); }
597 void CGeometryDoc::OnBUTTONTest49()
599 GeomSources::gpTest49(this); }
600 void CGeometryDoc::OnBUTTONTest50()
602 GeomSources::gpTest50(this); }
604 void CGeometryDoc::OnUpdateBUTTONTest1(CCmdUI* pCmdUI)
605 { if (Current == 1) pCmdUI->SetCheck(true);
606 else pCmdUI->SetCheck(false);
609 void CGeometryDoc::OnUpdateBUTTONTest2(CCmdUI* pCmdUI)
610 { if (Current == 2) pCmdUI->SetCheck(true);
611 else pCmdUI->SetCheck(false);
614 void CGeometryDoc::OnUpdateBUTTONTest3(CCmdUI* pCmdUI)
615 { if (Current == 3) pCmdUI->SetCheck(true);
616 else pCmdUI->SetCheck(false);
619 void CGeometryDoc::OnUpdateBUTTONTest4(CCmdUI* pCmdUI)
620 { if (Current == 4) pCmdUI->SetCheck(true);
621 else pCmdUI->SetCheck(false);
624 void CGeometryDoc::OnUpdateBUTTONTest5(CCmdUI* pCmdUI)
625 { if (Current == 5) pCmdUI->SetCheck(true);
626 else pCmdUI->SetCheck(false);
629 void CGeometryDoc::OnUpdateBUTTONTest6(CCmdUI* pCmdUI)
630 { if (Current == 6) pCmdUI->SetCheck(true);
631 else pCmdUI->SetCheck(false);
634 void CGeometryDoc::OnUpdateBUTTONTest7(CCmdUI* pCmdUI)
635 { if (Current == 7) pCmdUI->SetCheck(true);
636 else pCmdUI->SetCheck(false);
639 void CGeometryDoc::OnUpdateBUTTONTest8(CCmdUI* pCmdUI)
640 { if (Current == 8) pCmdUI->SetCheck(true);
641 else pCmdUI->SetCheck(false);
644 void CGeometryDoc::OnUpdateBUTTONTest9(CCmdUI* pCmdUI)
645 { if (Current == 9) pCmdUI->SetCheck(true);
646 else pCmdUI->SetCheck(false);
649 void CGeometryDoc::OnUpdateBUTTONTest10(CCmdUI* pCmdUI)
650 { if (Current == 10) pCmdUI->SetCheck(true);
651 else pCmdUI->SetCheck(false);
654 void CGeometryDoc::OnUpdateBUTTONTest11(CCmdUI* pCmdUI)
655 { if (Current == 11) pCmdUI->SetCheck(true);
656 else pCmdUI->SetCheck(false);
659 void CGeometryDoc::OnUpdateBUTTONTest12(CCmdUI* pCmdUI)
660 { if (Current == 12) pCmdUI->SetCheck(true);
661 else pCmdUI->SetCheck(false);
664 void CGeometryDoc::OnUpdateBUTTONTest13(CCmdUI* pCmdUI)
665 { if (Current == 13) pCmdUI->SetCheck(true);
666 else pCmdUI->SetCheck(false);
669 void CGeometryDoc::OnUpdateBUTTONTest14(CCmdUI* pCmdUI)
670 { if (Current == 14) pCmdUI->SetCheck(true);
671 else pCmdUI->SetCheck(false);
674 void CGeometryDoc::OnUpdateBUTTONTest15(CCmdUI* pCmdUI)
675 { if (Current == 15) pCmdUI->SetCheck(true);
676 else pCmdUI->SetCheck(false);
679 void CGeometryDoc::OnUpdateBUTTONTest16(CCmdUI* pCmdUI)
680 { if (Current == 16) pCmdUI->SetCheck(true);
681 else pCmdUI->SetCheck(false);
684 void CGeometryDoc::OnUpdateBUTTONTest17(CCmdUI* pCmdUI)
685 { if (Current == 17) pCmdUI->SetCheck(true);
686 else pCmdUI->SetCheck(false);
689 void CGeometryDoc::OnUpdateBUTTONTest18(CCmdUI* pCmdUI)
690 { if (Current == 18) pCmdUI->SetCheck(true);
691 else pCmdUI->SetCheck(false);
694 void CGeometryDoc::OnUpdateBUTTONTest19(CCmdUI* pCmdUI)
695 { if (Current == 19) pCmdUI->SetCheck(true);
696 else pCmdUI->SetCheck(false);
699 void CGeometryDoc::OnUpdateBUTTONTest20(CCmdUI* pCmdUI)
700 { if (Current == 20) pCmdUI->SetCheck(true);
701 else pCmdUI->SetCheck(false);
704 void CGeometryDoc::OnUpdateBUTTONTest21(CCmdUI* pCmdUI)
705 { if (Current == 21) pCmdUI->SetCheck(true);
706 else pCmdUI->SetCheck(false);
709 void CGeometryDoc::OnUpdateBUTTONTest22(CCmdUI* pCmdUI)
710 { if (Current == 22) pCmdUI->SetCheck(true);
711 else pCmdUI->SetCheck(false);
714 void CGeometryDoc::OnUpdateBUTTONTest23(CCmdUI* pCmdUI)
715 { if (Current == 23) pCmdUI->SetCheck(true);
716 else pCmdUI->SetCheck(false);
719 void CGeometryDoc::OnUpdateBUTTONTest24(CCmdUI* pCmdUI)
720 { if (Current == 24) pCmdUI->SetCheck(true);
721 else pCmdUI->SetCheck(false);
724 void CGeometryDoc::OnUpdateBUTTONTest25(CCmdUI* pCmdUI)
725 { if (Current == 25) pCmdUI->SetCheck(true);
726 else pCmdUI->SetCheck(false);
729 void CGeometryDoc::OnUpdateBUTTONTest26(CCmdUI* pCmdUI)
730 { if (Current == 26) pCmdUI->SetCheck(true);
731 else pCmdUI->SetCheck(false);
734 void CGeometryDoc::OnUpdateBUTTONTest27(CCmdUI* pCmdUI)
735 { if (Current == 27) pCmdUI->SetCheck(true);
736 else pCmdUI->SetCheck(false);
739 void CGeometryDoc::OnUpdateBUTTONTest28(CCmdUI* pCmdUI)
740 { if (Current == 28) pCmdUI->SetCheck(true);
741 else pCmdUI->SetCheck(false);
744 void CGeometryDoc::OnUpdateBUTTONTest29(CCmdUI* pCmdUI)
745 { if (Current == 29) pCmdUI->SetCheck(true);
746 else pCmdUI->SetCheck(false);
749 void CGeometryDoc::OnUpdateBUTTONTest30(CCmdUI* pCmdUI)
750 { if (Current == 30) pCmdUI->SetCheck(true);
751 else pCmdUI->SetCheck(false);
754 void CGeometryDoc::OnUpdateBUTTONTest31(CCmdUI* pCmdUI)
755 { if (Current == 31) pCmdUI->SetCheck(true);
756 else pCmdUI->SetCheck(false);
759 void CGeometryDoc::OnUpdateBUTTONTest32(CCmdUI* pCmdUI)
760 { if (Current == 32) pCmdUI->SetCheck(true);
761 else pCmdUI->SetCheck(false);
764 void CGeometryDoc::OnUpdateBUTTONTest33(CCmdUI* pCmdUI)
765 { if (Current == 33) pCmdUI->SetCheck(true);
766 else pCmdUI->SetCheck(false);
769 void CGeometryDoc::OnUpdateBUTTONTest34(CCmdUI* pCmdUI)
770 { if (Current == 34) pCmdUI->SetCheck(true);
771 else pCmdUI->SetCheck(false);
774 void CGeometryDoc::OnUpdateBUTTONTest35(CCmdUI* pCmdUI)
775 { if (Current == 35) pCmdUI->SetCheck(true);
776 else pCmdUI->SetCheck(false);
779 void CGeometryDoc::OnUpdateBUTTONTest36(CCmdUI* pCmdUI)
780 { if (Current == 36) pCmdUI->SetCheck(true);
781 else pCmdUI->SetCheck(false);
784 void CGeometryDoc::OnUpdateBUTTONTest37(CCmdUI* pCmdUI)
785 { if (Current == 37) pCmdUI->SetCheck(true);
786 else pCmdUI->SetCheck(false);
789 void CGeometryDoc::OnUpdateBUTTONTest38(CCmdUI* pCmdUI)
790 { if (Current == 38) pCmdUI->SetCheck(true);
791 else pCmdUI->SetCheck(false);
794 void CGeometryDoc::OnUpdateBUTTONTest39(CCmdUI* pCmdUI)
795 { if (Current == 39) pCmdUI->SetCheck(true);
796 else pCmdUI->SetCheck(false);
799 void CGeometryDoc::OnUpdateBUTTONTest40(CCmdUI* pCmdUI)
800 { if (Current == 40) pCmdUI->SetCheck(true);
801 else pCmdUI->SetCheck(false);
804 void CGeometryDoc::OnUpdateBUTTONTest41(CCmdUI* pCmdUI)
805 { if (Current == 41) pCmdUI->SetCheck(true);
806 else pCmdUI->SetCheck(false);
809 void CGeometryDoc::OnUpdateBUTTONTest42(CCmdUI* pCmdUI)
810 { if (Current == 42) pCmdUI->SetCheck(true);
811 else pCmdUI->SetCheck(false);
814 void CGeometryDoc::OnUpdateBUTTONTest43(CCmdUI* pCmdUI)
815 { if (Current == 43) pCmdUI->SetCheck(true);
816 else pCmdUI->SetCheck(false);
819 void CGeometryDoc::OnUpdateBUTTONTest44(CCmdUI* pCmdUI)
820 { if (Current == 44) pCmdUI->SetCheck(true);
821 else pCmdUI->SetCheck(false);
824 void CGeometryDoc::OnUpdateBUTTONTest45(CCmdUI* pCmdUI)
825 { if (Current == 45) pCmdUI->SetCheck(true);
826 else pCmdUI->SetCheck(false);
829 void CGeometryDoc::OnUpdateBUTTONTest46(CCmdUI* pCmdUI)
830 { if (Current == 46) pCmdUI->SetCheck(true);
831 else pCmdUI->SetCheck(false);
834 void CGeometryDoc::OnUpdateBUTTONTest47(CCmdUI* pCmdUI)
835 { if (Current == 47) pCmdUI->SetCheck(true);
836 else pCmdUI->SetCheck(false);
839 void CGeometryDoc::OnUpdateBUTTONTest48(CCmdUI* pCmdUI)
840 { if (Current == 48) pCmdUI->SetCheck(true);
841 else pCmdUI->SetCheck(false);
844 void CGeometryDoc::OnUpdateBUTTONTest49(CCmdUI* pCmdUI)
845 { if (Current == 49) pCmdUI->SetCheck(true);
846 else pCmdUI->SetCheck(false);
849 void CGeometryDoc::OnUpdateBUTTONTest50(CCmdUI* pCmdUI)
850 { if (Current == 50) pCmdUI->SetCheck(true);
851 else pCmdUI->SetCheck(false);
858 void CGeometryDoc::OnCloseDocument()
860 // TODO: Add your specialized code here and/or call the base class
862 CDocument::OnCloseDocument();
865 void CGeometryDoc::Fit()
867 CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
868 CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
869 OCC_3dView *pView = (OCC_3dView *) pChild->GetActiveView();
874 void CGeometryDoc::OnCreateSol()
876 // TODO: Add your command handler code here
878 CFileDialog dlg(TRUE,
881 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
882 "Points Files (*.dat)|*.dat; |All Files (*.*)|*.*||",
885 CString initdir(((OCC_BaseApp*) AfxGetApp())->GetInitDataDir());
886 initdir += "\\Data\\SurfaceFromPoints";
888 dlg.m_ofn.lpstrInitialDir = initdir;
890 if (dlg.DoModal() == IDOK)
892 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
893 CString filename = dlg.GetPathName();
897 if (!fic.open((Standard_CString)(LPCTSTR)filename,ios::in))
898 MessageBox(AfxGetApp()->m_pMainWnd->m_hWnd,"Error : Unable to open file","CasCade Error",MB_ICONERROR);
899 TColgp_SequenceOfXYZ seqOfXYZ;
901 Standard_Integer nbPnt=0;
906 while (!in.fail()|| !in.eof()){
907 if (in >> x && in >> y && in >> z){
912 seqOfXYZ.Append(pntXYZ);
913 BRepBuilderAPI_MakeVertex V(gp_Pnt(x, y, z));
918 Handle(AIS_Shape) anAISCompound = new AIS_Shape(C);
919 myAISContext->Display(anAISCompound, Standard_False);
925 if (sol.IsDone() == Standard_True){
926 Handle(Geom_BSplineSurface) GeomSol = sol.Surface();
927 TopoDS_Face aface = BRepBuilderAPI_MakeFace(GeomSol);
928 if (!BRepAlgo::IsValid(aface))
929 MessageBox(AfxGetApp()->m_pMainWnd->m_hWnd,"Error : The plate surface is not valid!","CasCade Error",MB_ICONERROR);
930 Handle_AIS_Shape anAISShape=new AIS_Shape(aface);
931 myAISContext->Display(anAISShape, Standard_False);
935 MessageBox(AfxGetApp()->m_pMainWnd->m_hWnd,"Error : Computation has failed","CasCade Error",MB_ICONERROR);
939 /*********************************************************************************************
940 ********************** S I M P L I F Y *****************************************************
941 *********************************************************************************************/
943 //================================================================
944 // Function : fixParam
945 // Purpose : assings a finite value to theParam if it intinite
946 // (equal to +- Precision::Infinite())
947 //================================================================
948 static Standard_Boolean fixParam(Standard_Real& theParam)
950 Standard_Boolean aResult = Standard_False;
951 if (Precision::IsNegativeInfinite(theParam))
953 theParam = -MAX_PARAM;
954 aResult = Standard_True;
956 if (Precision::IsPositiveInfinite(theParam))
958 theParam = MAX_PARAM;
959 aResult = Standard_True;
965 void CGeometryDoc::OnSimplify()
967 CString initfile(((OCC_BaseApp*) AfxGetApp())->GetInitDataDir());
968 initfile += "\\..\\..\\Data\\";
969 initfile += "shell1.brep";
971 TCollection_AsciiString Path((Standard_CString)(LPCTSTR)initfile);
975 //Standard_Boolean isRead = BRepTools::Read (aShape, aPath.ToCString(), aBld);
977 // isRead = BRepTools::Read (aShape, bPath.ToCString(), aBld);
978 Standard_Boolean isRead = BRepTools::Read (aShape, Path.ToCString(), aBld);
981 Path += " was not found. The sample can not be shown.";
982 myCResultDialog.SetText((CString)Path.ToCString());
986 myAISContext->SetDisplayMode(AIS_Shaded);
991 void CGeometryDoc::simplify(const TopoDS_Shape& aShape)
993 myCResultDialog.SetTitle(CString("Simplify Face"));
994 myCResultDialog.SetText((CString)
995 " TopoDS_Shape aShape;" EOL
997 " // initialize aShape" EOL
998 " //aShape = ..." EOL
1000 " // define parameter triangulation" EOL
1001 " Standard_Real aDeflection = 0.1;" EOL
1003 " // removes all the triangulations of the faces ," EOL
1004 " //and all the polygons on the triangulations of the edges" EOL
1005 " BRepTools::Clean(aShape);" EOL
1006 " // adds a triangulation of the shape aShape with the deflection aDeflection" EOL
1007 " BRepMesh::Mesh(aShape,aDeflection);" EOL
1009 " Standard_Integer aIndex = 1, nbNodes = 0;" EOL
1011 " // define two sequence of points" EOL
1012 " TColgp_SequenceOfPnt aPoints, aPoints1;" EOL
1014 " // triangulation" EOL
1015 " for(TopExp_Explorer aExpFace(aShape,TopAbs_FACE); aExpFace.More(); aExpFace.Next())" EOL
1017 " TopoDS_Face aFace = TopoDS::Face(aExpFace.Current());" EOL
1018 " TopLoc_Location aLocation;" EOL
1020 " // takes the triangulation of the face aFace" EOL
1021 " Handle_Poly_Triangulation aTr = BRep_Tool::Triangulation(aFace,aLocation);" EOL
1023 " if(!aTr.IsNull())" EOL
1025 " // takes the array of nodes for this triangulation" EOL
1026 " const TColgp_Array1OfPnt& aNodes = aTr->Nodes(); " EOL
1027 " nbNodes = aNodes.Length();" EOL
1029 " for( Standard_Integer i = 1; i <= nbNodes; i++)" EOL
1031 " // create seguence of node points in absolute coordinate system" EOL
1032 " gp_Pnt aPnt = aNodes(i).Transformed(aLocation);" EOL
1033 " aPoints.Append(aPnt);" EOL
1039 " // remove double points" EOL
1040 " nbNodes = aPoints.Length();" EOL
1041 " for( Standard_Integer i = 1; i <= nbNodes; i++)" EOL
1043 " gp_Pnt aPi = aPoints(i);" EOL
1044 " for( Standard_Integer j = i + 1; j < nbNodes; j++)" EOL
1046 " gp_Pnt aPj = aPoints(j);" EOL
1047 " if(!aPi.IsEqual(aPj,0.9))" EOL
1050 " if(aIndex == j - 1)" EOL
1051 " aPoints1.Append(aPi);" EOL
1053 " aIndex = i + 1;" EOL
1056 " // find max point" EOL
1058 " gp_Pnt aPntMax = aPoints1(1);" EOL
1059 " nbNodes = aPoints1.Length();" EOL
1060 " for(i = 2; i <= nbNodes; i++)" EOL
1062 " if(aPoints1(i).X() > aPntMax.X())" EOL
1065 " aPntMax = aPoints1(aIndex); " EOL
1069 " // clear seguence" EOL
1070 " aPoints.Clear();" EOL
1072 " Standard_Integer nbLeftNodes = nbNodes;" EOL
1074 " // ascending sort - fill aPoints with ascending " EOL
1075 " // by X coordinate points from aPoints1" EOL
1076 " for(i = 1; i < nbNodes; i++)" EOL
1078 " Standard_Real aMin = aPntMax.X();" EOL
1080 " for( Standard_Integer j = 1; j <= nbLeftNodes; j++)" EOL
1082 " if(aPoints1(j).X() < aMin)" EOL
1084 " aMin = aPoints1(j).X();" EOL
1088 " aPoints.Append(aPoints1(aIndex));" EOL
1089 " aPoints1.Remove(aIndex);" EOL
1090 " nbLeftNodes = aPoints1.Length();" EOL
1092 " aPoints.Append(aPntMax);" EOL
1094 " // define parameters GeomPlate_BuildPlateSurface" EOL
1095 " Standard_Integer Degree = 3;" EOL
1096 " Standard_Integer NbPtsOnCur = 10;" EOL
1097 " Standard_Integer NbIter = 3;" EOL
1098 " Standard_Integer Order = 0;" EOL
1099 " Standard_Integer MaxSeg = 9;" EOL
1100 " Standard_Integer MaxDegree = 5;" EOL
1101 " Standard_Real dmax, anApproxTol = 0.001;" EOL
1102 " Standard_Real aConstrTol = Precision::Confusion();" EOL
1104 " // define object BuildPlateSurface" EOL
1105 " GeomPlate_BuildPlateSurface BPSurf(Degree,NbPtsOnCur,NbIter);" EOL
1107 " // add point constraints to GeomPlate_BuildPlateSurface object" EOL
1108 " nbNodes = aPoints.Length();" EOL
1109 " for (i = 1; i <= nbNodes; i++)" EOL
1110 " BPSurf.Add(new GeomPlate_PointConstraint(aPoints(i), Order, aConstrTol));" EOL
1112 " BPSurf.Perform();" EOL
1114 " // make PlateSurface" EOL
1115 " Handle(GeomPlate_Surface) PSurf;" EOL
1116 " Handle(Geom_Surface) aSurf;" EOL
1118 " if (BPSurf.IsDone())" EOL
1120 " PSurf = BPSurf.Surface();" EOL
1122 " // define parameter approximation" EOL
1123 " dmax = Max(0.01,10*BPSurf.G0Error());" EOL
1125 " // make approximation" EOL
1126 " GeomPlate_MakeApprox Mapp(PSurf,anApproxTol, MaxSeg,MaxDegree,dmax);" EOL
1127 " aSurf = Mapp.Surface();" EOL
1132 " ShapeAnalysis_FreeBounds aFreeBounds(aShape, Standard_False, Standard_True);" EOL
1133 " TopoDS_Compound aClosedWires = aFreeBounds.GetClosedWires();" EOL
1134 " TopTools_IndexedMapOfShape aWires;" EOL
1135 " TopExp::MapShapes(aClosedWires, TopAbs_WIRE, aWires);" EOL
1136 " TopoDS_Wire aWire;" EOL
1137 " Standard_Integer nbWires = aWires.Extent();" EOL
1138 " if (nbWires) " EOL
1139 " aWire = TopoDS::Wire(aWires(1));" EOL
1143 " BRep_Builder B;" EOL
1144 " TopoDS_Face aFace;" EOL
1145 " B.MakeFace(aFace, aSurf, Precision::Confusion());" EOL
1146 " B.Add(aFace, aWire);" EOL
1147 " Handle_ShapeFix_Shape sfs = new ShapeFix_Shape(aFace);" EOL
1148 " sfs->Perform();" EOL
1149 " TopoDS_Shape aFixedFace = sfs->Shape();" EOL
1150 " if (aFixedFace.IsNull()) " EOL
1153 // define parameter triangulation
1154 Standard_Real aDeflection = 0.1;
1156 // removes all the triangulations of the faces ,
1157 //and all the polygons on the triangulations of the edges
1158 BRepTools::Clean(aShape);
1159 // adds a triangulation of the shape aShape with the deflection aDeflection
1160 BRepMesh::Mesh(aShape,aDeflection);
1162 Standard_Integer aIndex = 1, nbNodes = 0;
1164 // define two sequence of points
1165 TColgp_SequenceOfPnt aPoints, aPoints1;
1168 for(TopExp_Explorer aExpFace(aShape,TopAbs_FACE); aExpFace.More(); aExpFace.Next())
1170 TopoDS_Face aFace = TopoDS::Face(aExpFace.Current());
1171 TopLoc_Location aLocation;
1173 // takes the triangulation of the face aFace
1174 Handle_Poly_Triangulation aTr = BRep_Tool::Triangulation(aFace,aLocation);
1178 // takes the array of nodes for this triangulation
1179 const TColgp_Array1OfPnt& aNodes = aTr->Nodes();
1180 nbNodes = aNodes.Length();
1182 for( Standard_Integer i = 1; i <= nbNodes; i++)
1184 // create seguence of node points in absolute coordinate system
1185 gp_Pnt aPnt = aNodes(i).Transformed(aLocation);
1186 aPoints.Append(aPnt);
1192 // remove double points
1193 nbNodes = aPoints.Length();
1195 for( i = 1; i <= nbNodes; i++)
1197 gp_Pnt aPi = aPoints(i);
1199 for( j = i + 1; j < nbNodes; j++)
1201 gp_Pnt aPj = aPoints(j);
1202 if(!aPi.IsEqual(aPj,0.9))
1206 aPoints1.Append(aPi);
1213 gp_Pnt aPntMax = aPoints1(1);
1214 nbNodes = aPoints1.Length();
1215 for(i = 2; i <= nbNodes; i++)
1217 if(aPoints1(i).X() > aPntMax.X())
1220 aPntMax = aPoints1(aIndex);
1227 Standard_Integer nbLeftNodes = nbNodes;
1229 // ascending sort - fill aPoints with ascending
1230 // by X coordinate points from aPoints1
1231 for(i = 1; i < nbNodes; i++)
1233 Standard_Real aMin = aPntMax.X();
1235 for( Standard_Integer j = 1; j <= nbLeftNodes; j++)
1237 if(aPoints1(j).X() < aMin)
1239 aMin = aPoints1(j).X();
1243 aPoints.Append(aPoints1(aIndex));
1244 aPoints1.Remove(aIndex);
1245 nbLeftNodes = aPoints1.Length();
1247 aPoints.Append(aPntMax);
1249 // define parameters GeomPlate_BuildPlateSurface
1250 Standard_Integer Degree = 3;
1251 Standard_Integer NbPtsOnCur = 10;
1252 Standard_Integer NbIter = 3;
1253 Standard_Integer Order = 0;
1254 Standard_Integer MaxSeg = 9;
1255 Standard_Integer MaxDegree = 5;
1256 Standard_Real dmax, anApproxTol = 0.001;
1257 Standard_Real aConstrTol = Precision::Confusion();
1259 // define object BuildPlateSurface
1260 GeomPlate_BuildPlateSurface BPSurf(Degree,NbPtsOnCur,NbIter);
1262 // add point constraints to GeomPlate_BuildPlateSurface object
1263 nbNodes = aPoints.Length();
1264 for (i = 1; i <= nbNodes; i++)
1265 BPSurf.Add(new GeomPlate_PointConstraint(aPoints(i), Order, aConstrTol));
1269 // make PlateSurface
1270 Handle(GeomPlate_Surface) PSurf;
1271 Handle(Geom_Surface) aSurf;
1273 if (BPSurf.IsDone())
1275 PSurf = BPSurf.Surface();
1277 // define parameter approximation
1278 dmax = Max(0.01,10*BPSurf.G0Error());
1280 // make approximation
1281 GeomPlate_MakeApprox Mapp(PSurf,anApproxTol, MaxSeg,MaxDegree,dmax);
1282 aSurf = Mapp.Surface();
1287 ShapeAnalysis_FreeBounds aFreeBounds(aShape, Standard_False, Standard_True);
1288 TopoDS_Compound aClosedWires = aFreeBounds.GetClosedWires();
1289 TopTools_IndexedMapOfShape aWires;
1290 TopExp::MapShapes(aClosedWires, TopAbs_WIRE, aWires);
1292 Standard_Integer nbWires = aWires.Extent();
1294 aWire = TopoDS::Wire(aWires(1));
1300 B.MakeFace(aFace, aSurf, Precision::Confusion());
1301 B.Add(aFace, aWire);
1302 Handle_ShapeFix_Shape sfs = new ShapeFix_Shape(aFace);
1304 TopoDS_Shape aFixedFace = sfs->Shape();
1305 if (aFixedFace.IsNull())
1308 // output surface, make it half transparent
1309 Handle_AIS_InteractiveObject aSurfIO = drawSurface(
1310 aSurf, Quantity_NOC_LEMONCHIFFON3, Standard_False);
1311 aSurfIO->SetTransparency(0.5);
1312 myAISContext->Display(aSurfIO,Standard_False);
1315 if(WAIT_A_LITTLE) return;
1318 for(i = 1; i <= nbNodes; i++)
1319 drawPoint(aPoints(i));
1321 if(WAIT_A_LITTLE) return;
1323 // output resulting face
1324 drawShape(aFixedFace);
1327 Handle_AIS_InteractiveObject CGeometryDoc::drawSurface
1328 (const Handle_Geom_Surface& theSurface,
1329 const Quantity_Color& theColor,
1330 const Standard_Boolean toDisplay)
1332 Standard_Real u1, u2, v1, v2;
1333 theSurface->Bounds(u1,u2,v1,v2);
1339 Handle_AIS_Shape aGraphicSurface =
1340 new AIS_Shape(BRepBuilderAPI_MakeFace (theSurface, u1, u2, v1, v2));
1342 myAISContext->SetMaterial(aGraphicSurface, Graphic3d_NOM_PLASTIC, toDisplay);
1343 myAISContext->SetColor(aGraphicSurface, theColor, toDisplay);
1346 myAISContext->Display (aGraphicSurface, Standard_False);
1350 myAISContext->Display (aGraphicSurface);
1353 return aGraphicSurface;
1356 Standard_Boolean CGeometryDoc::WaitForInput (unsigned long aMilliSeconds)
1358 //::WaitForSingleObject(::CreateEvent (NULL, FALSE, FALSE, NULL), aMilliSeconds);
1359 if (::MsgWaitForMultipleObjects(0, NULL, FALSE, aMilliSeconds,
1360 QS_KEY | QS_MOUSEBUTTON) != WAIT_TIMEOUT)
1363 if (::PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
1365 if (msg.message == WM_KEYUP)
1367 ::PeekMessage (&msg, NULL, 0, 0, PM_REMOVE);
1368 return WaitForInput (aMilliSeconds);
1371 return Standard_True;
1374 return Standard_False;
1377 Handle_AIS_Point CGeometryDoc::drawPoint
1378 (const gp_Pnt& aPnt,
1379 const Quantity_Color& theColor,
1380 const Standard_Boolean toDisplay)
1382 Handle(AIS_Point) aGraphicPoint = new AIS_Point (new Geom_CartesianPoint(aPnt));
1384 myAISContext->SetColor (aGraphicPoint, theColor, toDisplay);
1386 myAISContext->Display (aGraphicPoint);
1387 //COCCDemoDoc::Fit();
1390 return aGraphicPoint;
1393 Handle_AIS_Shape CGeometryDoc::drawShape
1394 (const TopoDS_Shape& theShape,
1395 const Graphic3d_NameOfMaterial theMaterial,
1396 const Standard_Boolean toDisplay)
1398 Handle_AIS_Shape aGraphicShape = new AIS_Shape(theShape);
1400 myAISContext->SetMaterial(aGraphicShape, theMaterial, toDisplay);
1403 myAISContext->Display (aGraphicShape, Standard_False);
1407 myAISContext->Display (aGraphicShape);
1410 return aGraphicShape;