0024372: HLR Sample: erased objects are shown in HLR
[occt.git] / samples / mfc / standard / 01_Geometry / src / GeometryApp.cpp
1 // GeometryApp.cpp : Defines the class behaviors for the application.
2 //
3
4 #include "stdafx.h"
5
6 #include "GeometryApp.h"
7 #include "MainFrm.h"
8 #include "ChildFrm.h"
9 #include "GeometryDoc.h"
10 #include "GeometryView.h"
11 #include "GeometryView2d.h"
12 #include "ChildFrm2D.h"
13 #include "GeometryView2d.h"
14
15 /////////////////////////////////////////////////////////////////////////////
16 // CGeometryApp construction
17
18 CGeometryApp::CGeometryApp() : OCC_App()
19 {
20   SampleName = "Geometry"; //for about dialog
21   SetSamplePath ("..\\..\\01_Geometry");
22 }
23
24 CGeometryApp::~CGeometryApp()
25 {
26   delete pDocTemplateForView2d;
27 }
28 /////////////////////////////////////////////////////////////////////////////
29 // The one and only CGeometryApp object
30
31 CGeometryApp theApp;
32
33 /////////////////////////////////////////////////////////////////////////////
34 // CGeometryApp initialization
35
36 BOOL CGeometryApp::InitInstance()
37 {
38   AfxInitRichEdit();
39   AfxEnableControlContainer();
40
41   // Standard initialization
42   // If you are not using these features and wish to reduce the size
43   //  of your final executable, you should remove from the following
44   //  the specific initialization routines you do not need.
45
46   // Change the registry key under which our settings are stored.
47   // You should modify this string to be something appropriate
48   // such as the name of your company or organization.
49   SetRegistryKey(_T("Local AppWizard-Generated Applications"));
50
51   LoadStdProfileSettings();  // Load standard INI file options (including MRU)
52
53   // Register the application's document templates.  Document templates
54   //  serve as the connection between documents, frame windows and views.
55
56   pDocTemplateForView3d = new CMultiDocTemplate(
57     IDR_3DTYPE,
58     RUNTIME_CLASS(CGeometryDoc),
59     RUNTIME_CLASS(CChildFrame), // custom MDI child frame
60     RUNTIME_CLASS(CGeometryView));
61   AddDocTemplate(pDocTemplateForView3d);
62
63   pDocTemplateForView2d = new CMultiDocTemplate(
64     IDR_2DTYPE,
65     RUNTIME_CLASS(CGeometryDoc),
66     RUNTIME_CLASS(CChildFrame2D), // custom MDI child frame
67     RUNTIME_CLASS(CGeometryView2D));
68   //AddDocTemplate(pDocTemplateForView2d);
69
70   // create main MDI Frame window
71   CMainFrame* pMainFrame = new CMainFrame;
72   if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
73     return FALSE;
74   m_pMainWnd = pMainFrame;
75
76   // Parse command line for standard shell commands, DDE, file open
77   CCommandLineInfo cmdInfo;
78   ParseCommandLine(cmdInfo);
79
80   // Dispatch commands specified on the command line
81   if (!ProcessShellCommand(cmdInfo))
82     return FALSE;
83
84   // The main window has been initialized, so show and update it.
85   pMainFrame->ShowWindow(m_nCmdShow);
86   pMainFrame->UpdateWindow();
87
88   return TRUE;
89 }
90
91 /////////////////////////////////////////////////////////////////////////////
92 // CGeometryApp commands
93
94 //===================================================
95
96 CFrameWnd*  CGeometryApp::CreateView2D(CGeometryDoc* pDoc )
97 {
98   ASSERT_VALID(pDoc);
99   ASSERT_VALID(pDocTemplateForView2d);
100   CRuntimeClass * pViewClass = RUNTIME_CLASS(CGeometryView2D);
101   ASSERT(pViewClass != (CRuntimeClass *)NULL );
102   // Create a new frame window
103   CFrameWnd* pNewFrame = pDocTemplateForView2d->CreateNewFrame(pDoc, NULL);
104   pDocTemplateForView2d->InitialUpdateFrame(pNewFrame, pDoc);
105 return pNewFrame;
106 }
107
108 BOOL CGeometryApp::IsViewExisting(CDocument * pDoc, CRuntimeClass * pViewClass, CView * & pView)
109 {
110   ASSERT_VALID(pDoc);
111   ASSERT(pViewClass != (CRuntimeClass *)NULL );
112
113   POSITION position = pDoc->GetFirstViewPosition();
114   while (position != (POSITION)NULL)
115   {
116     CView* pCurrentView = pDoc->GetNextView(position);
117     ASSERT_VALID(pCurrentView);
118     if (pCurrentView->IsKindOf(pViewClass))
119     {
120       pView = pCurrentView;
121       return TRUE;
122     }
123   }
124   return FALSE;
125 }
126