home *** CD-ROM | disk | FTP | other *** search
/ The Houseplan Collection / HRCD2005.ISO / data1.cab / Zusatz / 3DS / DATA2.Z / DachHolzkonstructionDlg.cpp < prev    next >
C/C++ Source or Header  |  1999-04-28  |  6KB  |  206 lines

  1. // DachHolzkonstructionDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "DachHolzkonstruction.h"
  6. #include "DachHolzkonstructionDlg.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CDachHolzkonstructionDlg dialog
  16.  
  17. CDachHolzkonstructionDlg::CDachHolzkonstructionDlg(CWnd* pParent /*=NULL*/)
  18.     : CDialog(CDachHolzkonstructionDlg::IDD, pParent)
  19. {
  20.     //{{AFX_DATA_INIT(CDachHolzkonstructionDlg)
  21.         // NOTE: the ClassWizard will add member initialization here
  22.     //}}AFX_DATA_INIT
  23.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  24.   m_prog = NULL;
  25. }
  26.  
  27. void CDachHolzkonstructionDlg::DoDataExchange(CDataExchange* pDX)
  28. {
  29.     CDialog::DoDataExchange(pDX);
  30.     //{{AFX_DATA_MAP(CDachHolzkonstructionDlg)
  31.         // NOTE: the ClassWizard will add DDX and DDV calls here
  32.     //}}AFX_DATA_MAP
  33. }
  34.  
  35. BEGIN_MESSAGE_MAP(CDachHolzkonstructionDlg, CDialog)
  36.     //{{AFX_MSG_MAP(CDachHolzkonstructionDlg)
  37.     ON_WM_PAINT()
  38.     ON_WM_QUERYDRAGICON()
  39.     ON_BN_CLICKED(IDC_CREATE_ROOF, OnCreateRoof)
  40.     ON_WM_DESTROY()
  41.     //}}AFX_MSG_MAP
  42. END_MESSAGE_MAP()
  43.  
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CDachHolzkonstructionDlg message handlers
  46.  
  47. BOOL CDachHolzkonstructionDlg::OnInitDialog()
  48. {
  49.     CDialog::OnInitDialog();
  50.  
  51.     SetIcon(m_hIcon, TRUE);            // Set big icon
  52.     SetIcon(m_hIcon, FALSE);        // Set small icon
  53.     
  54.     // TODO: Add extra initialization here
  55.   if (FAILED(CoCreateInstance(CLSID_ArCon, NULL, CLSCTX_LOCAL_SERVER, IID_IArCon, (void**)&m_prog))) {
  56.     AfxMessageBox(IDS_NO_ARCON);
  57.     PostQuitMessage(0);
  58.     return TRUE;
  59.   }
  60.     
  61.     return TRUE;  // return TRUE  unless you set the focus to a control
  62. }
  63.  
  64. // If you add a minimize button to your dialog, you will need the code below
  65. //  to draw the icon.  For MFC applications using the document/view model,
  66. //  this is automatically done for you by the framework.
  67.  
  68. void CDachHolzkonstructionDlg::OnPaint() 
  69. {
  70.     if (IsIconic())
  71.     {
  72.         CPaintDC dc(this); // device context for painting
  73.  
  74.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  75.  
  76.         // Center icon in client rectangle
  77.         int cxIcon = GetSystemMetrics(SM_CXICON);
  78.         int cyIcon = GetSystemMetrics(SM_CYICON);
  79.         CRect rect;
  80.         GetClientRect(&rect);
  81.         int x = (rect.Width() - cxIcon + 1) / 2;
  82.         int y = (rect.Height() - cyIcon + 1) / 2;
  83.  
  84.         // Draw the icon
  85.         dc.DrawIcon(x, y, m_hIcon);
  86.     }
  87.     else
  88.     {
  89.         CDialog::OnPaint();
  90.     }
  91. }
  92.  
  93. HCURSOR CDachHolzkonstructionDlg::OnQueryDragIcon()
  94. {
  95.     return (HCURSOR) m_hIcon;
  96. }
  97.  
  98. void CDachHolzkonstructionDlg::OnDestroy() 
  99. {
  100.   if (m_prog) {
  101.     m_prog->Release();
  102.     m_prog = NULL;
  103.   }
  104.     CDialog::OnDestroy();
  105. }
  106.  
  107. void CDachHolzkonstructionDlg::OnCreateRoof() 
  108. {
  109.   VARIANT_BOOL result;
  110.  
  111.   // Makro mit ArCon verbinden
  112.   m_prog->StartMe((long)m_hWnd, NULL, &result);
  113.  
  114.   // Testen, ob ein Projekt geladen ist
  115.   long val;
  116.   m_prog->get_Mode(&val);
  117.   if (val == AC_NoMode) {
  118.     // Kein Projekt geladen, wir brauchen ein neues
  119.     IProject * prj;
  120.     m_prog->NewProject(&prj);
  121.     m_prog->CreateProject(prj);
  122.     prj->Release();
  123.   }
  124.  
  125.   // In den Konstruktionsmodus schalten
  126.   m_prog->put_Mode(AC_ModeConstruct);
  127.  
  128.   // Neue Dachkonstruktion beginnen
  129.   IRoofConstruction * constr;
  130.   m_prog->NewRoofConstruction(&constr);
  131.  
  132.   // erste DachflΣche definieren
  133.   constr->BeginNewArea(ACDACH_FlaecheEindeckung, &result);
  134.   constr->AddPoint(0.0, 0.0, 0.0, &result);
  135.   constr->AddPoint(10.0, 0.0, 0.0, &result);
  136.   constr->AddPoint(10.0, 4.0, 4.0, &result);
  137.   constr->AddPoint(0.0, 4.0, 4.0, &result);
  138.  
  139.   // zweite DachflΣchen definieren
  140.   constr->BeginNewArea(ACDACH_FlaecheEindeckung, &result);
  141.   constr->AddPoint(10.0, 8.0, 0.0, &result);
  142.   constr->AddPoint(0.0, 8.0, 0.0, &result);
  143.   constr->AddPoint(0.0, 4.0, 4.0, &result);
  144.   constr->AddPoint(10.0, 4.0, 4.0, &result);
  145.  
  146.   // Balken erzeugen
  147.   int i;
  148.   double dx;
  149.   const double PI = 3.1415926;
  150.   const double TexDirX = 0.0;
  151.   const double TexDirY = 45.0 * PI / 180.0;
  152.   const double TexDirZ = 90.0 * PI / 180.0;
  153.   const double dBreite = 0.08;
  154.   const double dDicke = 0.16;
  155.   const double dAbstand = 0.8;
  156.   
  157.   dx = 0.0;
  158.   
  159.   for (i = 0; i < 10; i++) {
  160.     // Neuer Sparren (der Name ist optional)
  161.     CString name;
  162.     name.LoadString(IDS_NAME_SPARREN);
  163.     constr->NewRafter(ACRWOOD_Sparren, name.AllocSysString(), dBreite, dDicke, &result);
  164.     // Ausrichtung festlegen
  165.     constr->RafterSetGeo(ACRAFTER_TextureDir, TexDirX, TexDirY, TexDirZ, &result);
  166.     // Erster Eckpunkt
  167.     constr->RafterSetGeo(ACRAFTER_Left1, dx + 0.2, 0.0, 0.0, &result);
  168.     constr->RafterSetGeo(ACRAFTER_Right1, dx + 0.28, 0.0, 0.0, &result);
  169.     // Zweiter Eckpunkt
  170.     constr->RafterSetGeo(ACRAFTER_Left1, dx + 0.2, 4.0, 4.0, &result);
  171.     constr->RafterSetGeo(ACRAFTER_Right1, dx + 0.28, 4.0, 4.0, &result);
  172.     // Dritter Eckpunkt
  173.     constr->RafterSetGeo(ACRAFTER_Left1, dx + 0.2, 4.0, 4.0 - 0.16 / 0.707, &result);
  174.     constr->RafterSetGeo(ACRAFTER_Right1, dx + 0.28, 4.0, 4.0 - 0.16 / 0.707, &result);
  175.     // Vierter Eckpunkt
  176.     constr->RafterSetGeo(ACRAFTER_Left1, dx + 0.2, 0.0, 0.0 - 0.16 / 0.707, &result);
  177.     constr->RafterSetGeo(ACRAFTER_Right1, dx + 0.28, 0.0, 0.0 - 0.16 / 0.707, &result);
  178.             
  179.     dx = dx + dAbstand;
  180.   }
  181.  
  182.   // Analyse der Geometrie durchfⁿhren (ohne automatische Unterfⁿllung)
  183.   constr->Analyze(FALSE, &result);
  184.  
  185.   // Alles klar?
  186.   BSTR err = NULL;
  187.   constr->get_Fehler(&err);
  188.   if (SysStringLen(err) > 0) {
  189.     CString msg(err);
  190.     AfxMessageBox(msg);
  191.   } else {
  192.     // Die Konstruktion ist vollstΣndig - Dach erzeugen
  193.     IRoof * roof = NULL;
  194.     IStory * story = NULL;
  195.     m_prog->get_CurrentStory(&story);
  196.     constr->CreateRoof(story, &roof);
  197.     if (story) story->Release();
  198.     if (roof) roof->Release();
  199.   }
  200.   SysFreeString(err);
  201.   constr->Release();
  202.  
  203.   // Fertig, Makro Verbindung zu ArCon terminieren
  204.   m_prog->EndMe();
  205. }
  206.