1 //#**************************************************************
2 //# filename:             WCDriver3DDlg.cpp
3 //#
4 //# author:               Gerstmayr, Vetyukov
5 //#
6 //# generated:
7 //# description:
8 //# comments:
9 //#
10 //# Copyright (c) 2003-2013 Johannes Gerstmayr, Linz Center of Mechatronics GmbH, Austrian
11 //# Center of Competence in Mechatronics GmbH, Institute of Technical Mechanics at the
12 //# Johannes Kepler Universitaet Linz, Austria. All rights reserved.
13 //#
14 //# This file is part of HotInt.
15 //# HotInt is free software: you can redistribute it and/or modify it under the terms of
16 //# the HOTINT license. See folder 'licenses' for more details.
17 //#
18 //# bug reports are welcome!!!
19 //# WWW:		www.hotint.org
20 //# email:	bug_reports@hotint.org or support@hotint.org
21 //#***************************************************************************************
22 
23 
24 
25 #include "stdafx.h"
26 
27 #include <strsafe.h>
28 
29 #include "ioincludes.h"
30 #include <time.h>
31 #include <sys/timeb.h>
32 
33 #include "WCDriver3DDlg.h"
34 #include "WCDriver3D.h"
35 #include "DialogReadText.h"
36 
37 #include "DlgOneEditCtrl.h"
38 #include "CustomEditDialog.h"
39 #include "CListDlg.h"
40 #include "TreeViewCustomEditDialog.h"
41 
42 
43 
44 
45 #ifdef _DEBUG
46 #define new DEBUG_NEW
47 #undef THIS_FILE
48 static char THIS_FILE[] = __FILE__;
49 #endif
50 
51 
52 // the name of the configuration file
53 #define CONFIG_FILE_NAME "hotint.cfg"
54 
55 
56 // width of the zone between the edit box and the image
57 #define NEUTRAL_ZONE_WIDTH 0
58 #define BUTTONS_OFFSET 4
59 
60 // the windows message identifier
61 #define WM_UPDATE_TEXT (WM_USER + 1)
62 #define WM_UPDATE_PLOT (WM_USER + 11)
63 #define	WM_START_COMPUTATION (WM_USER + 2)
64 
65 // the timer ID
66 #define OUTPUT_REFRESH_TIMER_ID (WM_USER + 101)
67 #define PLOTTOOL_REFRESH_TIMER_ID (WM_USER + 111)
68 
69 /////////////////////////////////////////////////////////////////////////////
70 // CAboutDlg dialog used for App About
71 
72 class CAboutDlg : public CDialog
73 {
74 public:
75 	CAboutDlg();
76 	void SetpWCDI(WCDInterface* pWCDIi);
77 	WCDInterface* pWCDI;
78 	// Dialog Data
79 	//{{AFX_DATA(CAboutDlg)
80 	enum { IDD = IDD_ABOUTBOX };
81 	//}}AFX_DATA
82 
83 	// ClassWizard generated virtual function overrides
84 	//{{AFX_VIRTUAL(CAboutDlg)
85 protected:
86 	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
87 	//}}AFX_VIRTUAL
88 
89 	BOOL OnInitDialog();
90 		// Implementation
91 protected:
92 	//{{AFX_MSG(CAboutDlg)
93 	//}}AFX_MSG
94 	DECLARE_MESSAGE_MAP()
95 public:
96 };
97 
CAboutDlg()98 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
99 {
100 	//{{AFX_DATA_INIT(CAboutDlg)
101 	//}}AFX_DATA_INIT
102 }
103 
SetpWCDI(WCDInterface * pWCDIi)104 void CAboutDlg::SetpWCDI(WCDInterface* pWCDIi)
105 {
106 	pWCDI = pWCDIi;
107 }
108 
OnInitDialog()109 BOOL CAboutDlg::OnInitDialog()
110 {
111 	CDialog::OnInitDialog();
112 
113 	char* str = pWCDI->GetHotintVersion().GetString();
114 
115 	CWnd * atext = GetDlgItem(IDC_ABOUTTEXT);
116 	CString cst = "HOTINT\n";
117 	cst += "A multibody system simulation software\n";
118 	cst += "Johannes Gerstmayr (main developer)\n\n";
119 	cst += "(HOTINT MBS) Version: ";
120   cst += str;
121   cst += "\nBuild Date: ";
122 	cst += __DATE__;
123 	//cst += " ";
124 	//cst += __TIME__;
125 	cst += "\n\n";
126 	cst += "Parts of HOTINT developed at: \nLCM, ACCM and Institute of Technical Mechanics (JKU Linz) \n(www.lcm.at, www.accm.co.at, tmech.mechatronik.uni-linz.ac.at)\n\n";
127 	cst += "Copyright (C) 2003-2013, Linz, Austria\n";
128 	cst += "www.hotint.org\n";
129 	cst += "email to: support@hotint.org";
130 
131 	atext->SetWindowText(cst);	// TODO: Add extra initialization here
132 
133 	return TRUE;  // return TRUE unless you set the focus to a control
134 	              // EXCEPTION: OCX Property Pages should return FALSE
135 }
136 
DoDataExchange(CDataExchange * pDX)137 void CAboutDlg::DoDataExchange(CDataExchange* pDX)
138 {
139 	CDialog::DoDataExchange(pDX);
140 	//{{AFX_DATA_MAP(CAboutDlg)
141 	//}}AFX_DATA_MAP
142 }
143 
BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)144 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
145 	//{{AFX_MSG_MAP(CAboutDlg)
146 	// No message handlers
147 	//}}AFX_MSG_MAP
148 END_MESSAGE_MAP()
149 
150 void ErrorExit(LPCTSTR lpszFunction)
151 {
152     // Retrieve the system error message for the last-error code
153 
154     LPVOID lpMsgBuf;
155     LPVOID lpDisplayBuf;
156     DWORD dw = GetLastError();
157 
158     FormatMessage(
159         FORMAT_MESSAGE_ALLOCATE_BUFFER |
160         FORMAT_MESSAGE_FROM_SYSTEM |
161         FORMAT_MESSAGE_IGNORE_INSERTS,
162         NULL,
163         dw,
164         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
165         (LPTSTR) &lpMsgBuf,
166         0, NULL );
167 
168     // Display the error message and exit the process
169 
170     lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
171         (lstrlen((LPCTSTR)lpMsgBuf)+lstrlen((LPCTSTR)lpszFunction)+40)*sizeof(TCHAR));
172     StringCchPrintf((LPTSTR)lpDisplayBuf,
173         LocalSize(lpDisplayBuf) / sizeof(TCHAR),
174         TEXT("%s failed with error %d: %s"),
175         lpszFunction, dw, lpMsgBuf);
176     MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK);
177 
178     LocalFree(lpMsgBuf);
179     LocalFree(lpDisplayBuf);
180     ExitProcess(dw);
181 }
182 
183 
184 /////////////////////////////////////////////////////////////////////////////
185 // CWCDriver3DDlg dialog
186 
CWCDriver3DDlg(CWnd * pParent)187 CWCDriver3DDlg::CWCDriver3DDlg(CWnd* pParent /*=NULL*/) :
188 CDialog(CWCDriver3DDlg::IDD, pParent),
189 bClosingDialog(false),
190 pWCDI(NULL)
191 {
192 	//{{AFX_DATA_INIT(CWCDriver3DDlg)
193 	m_ConsoleText = _T("");
194 	//}}AFX_DATA_INIT
195 	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
196 	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
197 	hCursCross = AfxGetApp()->LoadStandardCursor(IDC_CROSS);
198 	hCursDragHor = AfxGetApp()->LoadStandardCursor(IDC_SIZEWE);
199 
200 	//char buf[2000];
201 	//GetCurrentDirectory(2000,buf);
202 	//SetDllDirectoryA(buf);
203 
204 	hWorkingDll = AfxLoadLibrary(WORKING_DLL_NAME);
205 	if(!hWorkingDll)
206 	{
207 		//ofstream ofile("check_working_moduleDLL_path.tmp");
208 		//ofile.close();
209 		ErrorExit((LPCTSTR)(CString("HOTINT: Cannot load dynamic-link library: ") + WORKING_DLL_NAME + "!\n"));
210 	}
211 
212 	pExpFn = (PExpFn)(GetProcAddress(hWorkingDll,WORKING_OBJECT_CREATION_FUNCTION_NAME));
213 	if(!pExpFn)
214 		ErrorExit((LPCTSTR)(CString("Wrong dynamic-link library ") + WORKING_DLL_NAME + "!\n"));
215 
216 	asv_models.SetLength(0); //$ DR 2013-05-21
217 }
218 
~CWCDriver3DDlg()219 CWCDriver3DDlg::~CWCDriver3DDlg()
220 {
221 	//$ YV 2013-01-04: leads to a crash
222 	//DeleteCriticalSection(&uses_append_text);
223 	//if crashes: put ! in if and put the destroy window operations after FreeLibrary
224 	if(::IsWindow(DialogDataManager.m_hWnd))
225 		DialogDataManager.DestroyWindow();
226 
227 	if(::IsWindow(DialogFEDrawingOptions.m_hWnd))
228 		DialogFEDrawingOptions.DestroyWindow();
229 
230 	if(::IsWindow(dialogComputationOutput.m_hWnd))
231 		dialogComputationOutput.DestroyWindow();
232 
233 	if(::IsWindow(dialogViewingOptions.m_hWnd))
234 		dialogViewingOptions.DestroyWindow();
235 
236 	//if(::IsWindow(dialogComputationSettings.m_hWnd))		//$ DR 2013-10-16 removed
237 	//	dialogComputationSettings.DestroyWindow();
238 
239 	if(::IsWindow(dialogBodyJointOptions.m_hWnd))
240 		dialogBodyJointOptions.DestroyWindow();
241 
242 	if(::IsWindow(computeEigenmodes.m_hWnd))
243 		computeEigenmodes.DestroyWindow();
244 
245 	if(::IsWindow(dialogProgressbar.m_hWnd))
246 		dialogProgressbar.DestroyWindow();
247 
248 	if(::IsWindow(Dialog2DView.m_hWnd))            //!AD: maybe put that in WCDriverFunction too, nested views seem to be a problem here
249 		Dialog2DView.DestroyWindow();
250 
251 	CallWCDriverFunction(9);											 // close all instances of PlotToolDlgs
252 
253 	for (int i=0; i < MAX_SENSOR_WATCH; i++)
254 	{
255 		if (sensorwatchctrl[i])
256 		{
257 			if (::IsWindow(sensorwatchctrl[i]->m_hWnd))
258 				sensorwatchctrl[i]->DestroyWindow();
259 			delete sensorwatchctrl[i];
260 		}
261 	}
262 
263 	if(pWCDI)
264 		delete pWCDI;
265 
266 	FreeLibrary(hWorkingDll);
267 
268 
269 }
270 
DoDataExchange(CDataExchange * pDX)271 void CWCDriver3DDlg::DoDataExchange(CDataExchange* pDX)
272 {
273 	CDialog::DoDataExchange(pDX);
274 	/*
275 	//{{AFX_DATA_MAP(CWCDriver3DDlg)
276 	DDX_Text(pDX, IDC_EDIT_CONSOLE, m_ConsoleText);
277 	//}}AFX_DATA_MAP
278 	*/
279 }
280 
281 //ON_WM_INITMENUPOPUP() has been added such that menu check and change status works in the dialog!!!
BEGIN_MESSAGE_MAP(CWCDriver3DDlg,CDialog)282 BEGIN_MESSAGE_MAP(CWCDriver3DDlg, CDialog)
283 	//{{AFX_MSG_MAP(CWCDriver3DDlg)
284 	ON_WM_INITMENUPOPUP()
285 	ON_WM_SYSCOMMAND()
286 	ON_WM_QUERYDRAGICON()
287 	ON_WM_SIZE()
288 	ON_BN_CLICKED(IDC_BUTTON_GO, OnButtonGo)
289 	ON_BN_CLICKED(IDC_BUTTON_PAUSE, OnButtonPause)
290 	ON_WM_PAINT()
291 	ON_WM_LBUTTONDOWN()
292 	ON_WM_MOUSEMOVE()
293 	ON_WM_LBUTTONUP()
294 	ON_WM_CLOSE()
295 	ON_MESSAGE(WM_UPDATE_TEXT,OnUpdateText)
296 	ON_MESSAGE(WM_START_COMPUTATION, OnButtonGoMessage) //added by JG manually
297 	//}}AFX_MSG_MAP
298 	ON_BN_CLICKED(IDC_BUTTON_GENERALOPTIONS, OnBnClickedButtonGeneraloptions)
299 	ON_COMMAND(ID_RESULTS_DATAMANAGER, OnResultsDatamanager)
300 	ON_COMMAND(ID_RESULTS_VIEWOUTPUT, OnResultsViewoutput)
301 	ON_COMMAND(ID_COMPUTATION_RESET, OnComputationReset)
302 	ON_COMMAND(ID_COMPUTATION_PRINTTIMINGS, OnComputationPrinttimings)
303 	ON_COMMAND(ID_RESULTS_SHOWOUTPUTSTATICTEXT, OnResultsShowoutputstatictext)
304 	ON_COMMAND(ID_OPTIONS_SAVECONFIGURATION, OnOptionsSaveconfiguration)
305 	ON_COMMAND(ID_OPTIONS_SAVESOLVEROPTIONS, OnOptionsSaveSolverOptions)
306 	ON_COMMAND(ID_OPTIONS_SAVEHOTINTOPTIONS, OnOptionsSaveHotintOptions)
307 	ON_COMMAND(ID_RESULTS_ENABLEOUTPUT, OnResultsEnableoutput)
308 	ON_WM_MOVE()
309 	ON_COMMAND(ID_VIEW_FE_DRAWINGOPTIONS, OnViewFeDrawingoptions)
310 	ON_COMMAND(ID_VIEW_VIEWINGOPTIONS, OnViewViewingoptions)
311 	//	ON_WM_KEYUP()
312 	//ON_COMMAND(ID_COMPUTATION_COMPUTATIONOPTIONS, OnComputationComputationoptions)	//$ DR 2013-10-16 removed
313   	ON_COMMAND(ID_COMPUTATION_COMPUTEEIGENMODES, OnComputationComputeEigenmodes)
314 	ON_COMMAND(ID_VIEW_RIGIDBODY, OnViewRigidbodyJointOptions)
315 	ON_COMMAND(ID_EDIT_EDITBODY, OnEditEditbody)
316 	//ON_COMMAND(ID_COMPUTATION_ASSEMBLESYSTEM, OnComputationAssemblesystem)
317 	ON_COMMAND(ID_VIEW_OPENGLOPTIONS, OnViewOpengloptions)
318 	//ON_COMMAND(ID_RIGIDBODIES_ADDMASS3D, OnRigidbodiesAddmass3d)
319 	//ON_COMMAND(ID_COMPUTATION_ASSIGNINITIALVECTOR, OnComputationAssigninitialvector)
320 	//ON_COMMAND(ID_RIGIDBODY_ADDRIGID3D, OnRigidbodyAddrigid3d)
321 	//ON_COMMAND(ID_3DJOINT_SPHERICALJOINT, On3djointSphericaljoint)
322 	//ON_COMMAND(ID_3DJOINT_REVOLUTEJOINT, On3djointRevolutejoint)
323 	ON_COMMAND(ID_FILE_EXIT, OnFileExit)
324 	ON_COMMAND(ID_FILE_NEWMBS, OnFileNewmbs)
325 	//ON_COMMAND(ID_ADDLOAD_GCLOAD, OnAddloadGcload)
326 	//ON_COMMAND(ID_ADDLOAD_BODYLOAD, OnAddloadBodyload)
327 	//ON_COMMAND(ID_ADDLOAD_FORCEVECTOR2D, OnAddloadForcevector2d)
328 	//ON_COMMAND(ID_ADDLOAD_MOMENT2D, OnAddloadMoment2d)
329 	//ON_COMMAND(ID_ADDLOAD_FORCEVECTOR3D, OnAddloadForcevector3d)
330 	//ON_COMMAND(ID_ADDLOAD_MOMENTVECTOR3D, OnAddloadMomentvector3d)
331 //	ON_COMMAND(ID_JOINTS_ADDJOINT, OnJointsAddjoint)
332 	ON_COMMAND(ID_FILE_SAVEMBS, OnFileSavembs)
333 	ON_COMMAND(ID_EDIT_EDITSENSOR, OnEditEditsensor)
334 	ON_COMMAND(ID_FILE_OPENMBS, OnFileOpenmbs)
335 	ON_COMMAND(ID_FILE_SAVEMBSAS, OnFileSavembsas)
336 	ON_COMMAND(ID_SPECIAL_ADDSENSOR, OnSpecialAddsensor)
337 	ON_COMMAND(ID_RESULTS_PLOTSENSOR, OnResultsPlotsensor)
338 	ON_COMMAND(ID_SPECIAL_ADDBODY, OnSpecialAddbody)
339 	ON_COMMAND(ID_RESULTS_SENSORWATCH, OnResultsSensorwatch)
340 	ON_COMMAND(ID_FILE_RECENTFILE1, OnFileRecentfile1)
341 	ON_BN_CLICKED(IDC_BUTTON_RECENT_FILE, OnBnClickedButtonRecentFile)
342 	ON_COMMAND(ID_SPECIAL_ADDGEOMELEMENT, OnSpecialAddgeomelement)
343 	ON_COMMAND(ID_EDIT_EDITGEOMELEMENT, OnEditEditgeomelement)
344 	//ON_COMMAND(ID_ADDCONNECTOR_JOINT, OnAddconnectorJoint2D)
345 	//ON_COMMAND(ID_ADDCONNECTOR_3DJOINT, OnAddConnectorJoint3D)
346 	//ON_COMMAND(ID_ADDCONNECTOR_SPECIAL, OnAddconnectorSpecial)
347 	ON_COMMAND(ID_SYSTEM_SHOWSYSTEMPROPERTIES, OnSystemShowsystemproperties)
348 	ON_COMMAND(ID_ADDOBJECT_ADDNODE, OnAddobjectAddnode)
349 	ON_COMMAND(ID_EDIT_EDITNODE, OnEditEditnode)
350 	ON_COMMAND(ID_SYSTEM_CHECKSYSTEM, OnSystemChecksystem)
351 	ON_COMMAND(ID__ABOUT, OnHelpAbout)
352 	ON_COMMAND(ID_VIEW_DEFAULTVIEW1, OnViewDefaultview1)
353 	ON_COMMAND(ID_VIEW_XY, OnViewXY)
354 	ON_COMMAND(ID_VIEW_XZ, OnViewXZ)
355 	ON_COMMAND(ID_VIEW_YZ, OnViewYZ)
356 	ON_WM_MOUSEWHEEL()
357 	ON_COMMAND(ID_COMPUTATION_LOADINITIALVECTOR, OnComputationLoadinitialvector)
358 	ON_COMMAND(ID_COMPUTATION_STORESOLUTIONVECTOR, OnComputationStoresolutionvector)
359 	//ON_COMMAND(ID_EDIT_CHANGEELEMENTNUMBERS, OnEditChangeelementnumbers)
360 	ON_COMMAND(ID__HELP, OnMenuHelp)
361 	ON_COMMAND(ID_VIEW_ROBOTOPTIONS, OnViewRobotoptions)
362 	ON_COMMAND(ID_EDIT_EDITMATERIAL, OnEditEditmaterial)
363 	ON_COMMAND(ID_VIEW_SAVECONFIGURATION, OnOptionsSaveconfiguration)
364 	ON_COMMAND(ID_SYSTEM_EDITMODELPARAMETERS, &CWCDriver3DDlg::OnSystemEditmodelparameters)
365 	ON_COMMAND(ID_SYSTEM_LOADMODELPARAMETER, &CWCDriver3DDlg::OnSystemLoadmodelparameter)
366 	ON_COMMAND(ID_SYSTEM_SAVEMODELDATA, &CWCDriver3DDlg::OnSystemSavemodeldata)
367 	ON_COMMAND(ID_VIEW_EDITALLOPTIONS, &CWCDriver3DDlg::OnViewEditalloptions)
368 	ON_WM_TIMER()
369 	ON_COMMAND(ID_RESULTS_PLOT2SENSORSXY, &CWCDriver3DDlg::OnResultsPlot2sensorsxy)
370 	//ON_COMMAND(ID_RESULTS_PLOTNSENSORS, &CWCDriver3DDlg::OnResultsPlotnsensors)
371 	ON_COMMAND(ID_VIEW_SHOWPROGRESSBAR, &CWCDriver3DDlg::OnViewShowprogressbar)
372 	ON_COMMAND(ID_RESULTS_PLOTTOOLDIALOG, &CWCDriver3DDlg::OnResultsPlottooldialog)
373 	ON_COMMAND(ID_FILE_SELECTMODEL, &CWCDriver3DDlg::OnFileSelectmodel)
374 	ON_COMMAND(ID_EDIT_EDITSOLVEROPTIONS, &CWCDriver3DDlg::OnEditEditsolveroptions)
375 	ON_COMMAND(ID_EDIT_EDITHOTINTOPTIONS, &CWCDriver3DDlg::OnEditEdithotintoptions)
376 	ON_COMMAND(ID_COMPUTATION_EDITCOMPUTATIONSTEPS, &CWCDriver3DDlg::OnEditComputationSteps)
377 	ON_COMMAND(ID_EDIT_EDITLOAD, &CWCDriver3DDlg::OnEditEditLoad)
378 	ON_COMMAND(ID_ADDOBJECT_ADDLOAD, &CWCDriver3DDlg::OnAddload)
379 	ON_COMMAND(ID_VIEW_SHOW_IO_BLOCKS_WINDOW, &CWCDriver3DDlg::OnViewShowContolWindow)
380 	ON_COMMAND(ID_ADDOBJECT_ADDMATERIAL, &CWCDriver3DDlg::OnAddobjectAddmaterial)
381 	ON_COMMAND(ID_ADDOBJECT_ADDBEAM3DPROPERTIES, &CWCDriver3DDlg::OnAddbeam3dproperties)
382 	ON_WM_KEYDOWN()
383 	ON_COMMAND(ID_ADDCONNECTOR_KINEMATICPAIRS, &CWCDriver3DDlg::OnAddconnectorKinematicpairs)
384 	ON_COMMAND(ID_ADDCONNECTOR_CONTROLELEMENT, &CWCDriver3DDlg::OnAddconnectorControlelement)
385 	ON_BN_CLICKED(IDC_BUTTON_SAVE_MBS, &CWCDriver3DDlg::OnBnClickedButtonSaveMbs)
386 	ON_COMMAND(ID_EDIT_DELETELOAD32963, &CWCDriver3DDlg::OnEditDeleteLoad)
387 	ON_COMMAND(ID_EDIT_DELETEGEOMELEMENT32964, &CWCDriver3DDlg::OnEditDeleteGeomelement)
388 	ON_COMMAND(ID_EDIT_DELETESENSOR32965, &CWCDriver3DDlg::OnEditDeleteSensor)
389 	ON_COMMAND(ID_EDIT_DELETENODE32966, &CWCDriver3DDlg::OnEditDeleteNode)
390 	ON_COMMAND(ID_EDIT_DELETEMATERIAL32967, &CWCDriver3DDlg::OnEditDeleteMaterial)
391 	ON_COMMAND(ID_EDIT_DELETEELEMENT32968, &CWCDriver3DDlg::OnEditDeleteElement)
392 	ON_COMMAND(ID_EDIT_UNDO32969, &CWCDriver3DDlg::OnEditUndo)
393 	ON_COMMAND(ID_SYSTEM_RUNMACRO, &CWCDriver3DDlg::OnSystemRunmacro)
394 	END_MESSAGE_MAP()
395 
396 /////////////////////////////////////////////////////////////////////////////
397 // CWCDriver3DDlg message handlers
398 
399 BOOL CWCDriver3DDlg::OnInitDialog()
400 {
401 	CDialog::OnInitDialog();
402 
403 	fileopened = 0;
404 	model_modified = 0;
405 	enableOutputText = 1;
406 
407 
408 	// Set the icon for this dialog.  The framework does this automatically
409 	//  when the application's main window is not a dialog
410 	SetIcon(m_hIcon, TRUE);			// Set big icon
411 	SetIcon(m_hIcon, FALSE);		// Set small icon
412 
413 	pWCDI = (*pExpFn)();
414 	pWCDI->SetUserInterface(this);
415 	GLDrawWnd.SetWCDI(pWCDI);
416 
417 	GetClientRect(&PictureRect);
418 	//CRect EditRect;
419 	//GetDlgItem(IDC_EDIT_CONSOLE)->GetWindowRect(&EditRect);
420 	CRect GoButtonRect;
421 	GetDlgItem(IDC_BUTTON_GO)->GetWindowRect(&GoButtonRect);
422 	PictureRect.left = /*EditRect.Width() + */  NEUTRAL_ZONE_WIDTH;
423 	PictureRect.top = GoButtonRect.Height();
424 
425 	//PositionButtons();
426 
427 	DialogDataManager.SetWCDI(pWCDI);
428 	DialogDataManager.SetGLDrawWnd(&GLDrawWnd);
429 
430 	DialogFEDrawingOptions.SetWCDI(pWCDI);
431 	DialogFEDrawingOptions.SetGLDrawWnd(&GLDrawWnd);
432 
433 	dialogViewingOptions.SetWCDI(pWCDI);
434 	dialogViewingOptions.SetGLDrawWnd(&GLDrawWnd);
435 
436 	//dialogComputationSettings.SetWCDI(pWCDI);		//$ DR 2013-10-16 removed
437 	//dialogComputationSettings.SetGLDrawWnd(&GLDrawWnd);
438 
439 	dialogBodyJointOptions.SetWCDI(pWCDI);
440 	dialogBodyJointOptions.SetGLDrawWnd(&GLDrawWnd);
441 
442 	dialogOpenGLOptions.SetWCDI(pWCDI);
443 	dialogOpenGLOptions.SetGLDrawWnd(&GLDrawWnd);
444 
445 	computeEigenmodes.SetWCDI(pWCDI);
446 	computeEigenmodes.SetGLDrawWnd(&GLDrawWnd);
447 	computeEigenmodes.SetWCDDlg(this);
448 
449 	dialogProgressbar.SetWCDI(pWCDI);
450 	dialogProgressbar.SetGLDrawWnd(&GLDrawWnd);
451 
452 	Dialog2DView.SetWCDI(pWCDI);
453 	Dialog2DView.SetWCDDlg(this);
454 	//Dialog2DView.SetGLDrawWnd(&GLDrawWnd);
455 
456 	//appPlotTool = AfxBeginThread((CRuntimeClass*)RUNTIME_CLASS(CPlotToolApp));
457  // dialogPlotTool.SetWCDI(pWCDI);
458 	//dialogPlotTool.SetGLDrawWnd(&GLDrawWnd);
459 
460 	//do this after setting user interface
461 	ReadConfigFile();
462 	pWCDI->InitializeAfterConfigLoaded();
463 	DisplaySelectedModelName();
464 
465 	GLDrawWnd.Create(
466 		NULL,NULL,
467 		WS_CHILD | WS_BORDER | WS_VISIBLE,
468 		PictureRect,this,0
469 		);
470 
471   for (int i=0; i < MAX_SENSOR_WATCH; i++)
472 	{
473 		sensorwatchctrl[i] = 0;
474 	}
475 
476 	if (strlen(pWCDI->GetTOption(101)) > 0)
477 	{
478 		CMenu* mmenu = GetMenu();
479 		mmenu->ModifyMenu(ID_FILE_RECENTFILE1, MF_BYCOMMAND, ID_FILE_RECENTFILE1, CString("&Recent: ")+CString(pWCDI->GetTOption(94)));
480 		mmenu->EnableMenuItem(ID_FILE_RECENTFILE1, MF_BYCOMMAND | MF_ENABLED); //MF_DISABLED | MF_GRAYED
481 	}
482 	else
483 	{
484 		CMenu* mmenu = GetMenu();
485 		mmenu->EnableMenuItem(ID_FILE_RECENTFILE1, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); //
486 	}
487 
488 
489 ////#ifndef KB_INCLUDES
490 //	{
491 //	//robot options: --> deprecated ==> always disabled
492 //	CMenu* mmenu = GetMenu();
493 //	//mmenu->EnableMenuItem(ID_VIEW_ROBOTOPTIONS, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); //
494 //	mmenu->RemoveMenu(ID_VIEW_ROBOTOPTIONS, MF_BYCOMMAND);
495 //	}
496 
497 //#endif
498 
499 
500 	RemoveExperimentalMenuItems();
501 
502 	//start automatically:
503 	int autostart_flag;
504 	pWCDI->MBS_EDC_TreeGetInt(autostart_flag, "GeneralOptions.Application.start_computation_automatically");
505 	if (autostart_flag)
506 	{
507 		PostMessage(WM_START_COMPUTATION);
508 	}
509 
510 	// minimize window if IOption(221) = "GeneralOptions.Application.show_hotint_window" is set to zero
511 	int showwindow_flag;
512 	pWCDI->MBS_EDC_TreeGetInt(showwindow_flag, "GeneralOptions.Application.show_hotint_window");
513 	if (!showwindow_flag)
514 		ShowWindow(SW_SHOWMINNOACTIVE);
515 
516 	return TRUE;  // return TRUE  unless you set the focus to a control
517 }
518 
RemoveExperimentalMenuItems()519 void CWCDriver3DDlg::RemoveExperimentalMenuItems()
520 {
521 #ifdef __EXCLUDE_EXPERIMENTAL_MENU_ITEMS__
522 	CMenu* mmenu = GetMenu();
523 
524 	//// ?
525 	mmenu->RemoveMenu(ID__HELP, MF_BYCOMMAND);
526 
527 	//// Computation
528 	mmenu->RemoveMenu(ID_COMPUTATION_RESET, MF_BYCOMMAND);
529 	mmenu->RemoveMenu(ID_COMPUTATION_START, MF_BYCOMMAND);
530 	mmenu->RemoveMenu(ID_COMPUTATION_STOP, MF_BYCOMMAND);
531 	mmenu->RemoveMenu(ID_COMPUTATION_PAUSE, MF_BYCOMMAND);
532 	mmenu->RemoveMenu(ID_COMPUTATION_LOADINITIALVECTOR, MF_BYCOMMAND);
533 	mmenu->RemoveMenu(ID_COMPUTATION_STORESOLUTIONVECTOR, MF_BYCOMMAND);
534 	mmenu->RemoveMenu(ID_COMPUTATION_PRINTTIMINGS, MF_BYCOMMAND);
535 	mmenu->RemoveMenu(ID_COMPUTATION_COMPUTEEIGENMODES, MF_BYCOMMAND);
536 
537 	//// System
538 	mmenu->RemoveMenu(5, MF_BYPOSITION);
539 
540 	//// Add Object
541 	mmenu->RemoveMenu(4, MF_BYPOSITION);
542 
543 	//// Edit
544 	mmenu->RemoveMenu(3, MF_BYPOSITION);
545 
546 	//// View
547 	mmenu->RemoveMenu(ID_VIEW_SHOWPROGRESSBAR, MF_BYCOMMAND);
548 
549 	//// File
550 	mmenu->RemoveMenu(ID_FILE_NEWMBS, MF_BYCOMMAND);
551 	mmenu->RemoveMenu(ID_FILE_OPENMBS, MF_BYCOMMAND);
552 	mmenu->RemoveMenu(ID_FILE_SAVEMBS, MF_BYCOMMAND);
553 	mmenu->RemoveMenu(ID_FILE_SAVEMBSAS, MF_BYCOMMAND);
554 	mmenu->RemoveMenu(ID_FILE_RECENTFILE1, MF_BYCOMMAND);
555 
556 	//// finally, remove menu bars
557 	//mmenu->GetSubMenu(4)->RemoveMenu(2, MF_BYPOSITION);
558 	//mmenu->GetSubMenu(2)->RemoveMenu(4, MF_BYPOSITION);
559 	//mmenu->GetSubMenu(2)->RemoveMenu(3, MF_BYPOSITION);
560 	//mmenu->GetSubMenu(2)->RemoveMenu(2, MF_BYPOSITION);
561 	//mmenu->GetSubMenu(1)->RemoveMenu(0, MF_BYPOSITION);
562 	//mmenu->GetSubMenu(0)->RemoveMenu(4, MF_BYPOSITION);
563 	//mmenu->GetSubMenu(0)->RemoveMenu(4, MF_BYPOSITION);
564 	//mmenu->GetSubMenu(0)->RemoveMenu(2, MF_BYPOSITION);
565 	//mmenu->GetSubMenu(0)->RemoveMenu(1, MF_BYPOSITION);
566 
567 	// remove edit-dialog which shows modelname
568 	GetDlgItem(IDC_EDIT_MODELNAME)->ModifyStyle(WS_VISIBLE,0,0);
569 #endif
570 }
571 
572 //add this such that menu check, change text, etc. works in dialog with menu!!!
OnInitMenuPopup(CMenu * pPopupMenu,UINT nIndex,BOOL bSysMenu)573 void CWCDriver3DDlg::OnInitMenuPopup(CMenu *pPopupMenu, UINT nIndex,BOOL bSysMenu)
574 {
575 	ASSERT(pPopupMenu != NULL);
576 	// Check the enabled state of various menu items.
577 
578 	CCmdUI state;
579 	state.m_pMenu = pPopupMenu;
580 	ASSERT(state.m_pOther == NULL);
581 	ASSERT(state.m_pParentMenu == NULL);
582 
583 	// Determine if menu is popup in top-level menu and set m_pOther to
584 	// it if so (m_pParentMenu == NULL indicates that it is secondary popup).
585 	HMENU hParentMenu;
586 	if (AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu)
587 		state.m_pParentMenu = pPopupMenu;    // Parent == child for tracking popup.
588 	else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
589 	{
590 		CWnd* pParent = this;
591 		// Child windows don't have menus--need to go to the top!
592 		if (pParent != NULL &&
593 			(hParentMenu = ::GetMenu(pParent->m_hWnd)) != NULL)
594 		{
595 			int nIndexMax = ::GetMenuItemCount(hParentMenu);
596 			for (int nIndex = 0; nIndex < nIndexMax; nIndex++)
597 			{
598 				if (::GetSubMenu(hParentMenu, nIndex) == pPopupMenu->m_hMenu)
599 				{
600 					// When popup is found, m_pParentMenu is containing menu.
601 					state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
602 					break;
603 				}
604 			}
605 		}
606 	}
607 
608 	state.m_nIndexMax = pPopupMenu->GetMenuItemCount();
609 	for (state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax;
610 		state.m_nIndex++)
611 	{
612 		state.m_nID = pPopupMenu->GetMenuItemID(state.m_nIndex);
613 		if (state.m_nID == 0)
614 			continue; // Menu separator or invalid cmd - ignore it.
615 
616 		ASSERT(state.m_pOther == NULL);
617 		ASSERT(state.m_pMenu != NULL);
618 		if (state.m_nID == (UINT)-1)
619 		{
620 			// Possibly a popup menu, route to first item of that popup.
621 			state.m_pSubMenu = pPopupMenu->GetSubMenu(state.m_nIndex);
622 			if (state.m_pSubMenu == NULL ||
623 				(state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
624 				state.m_nID == (UINT)-1)
625 			{
626 				continue;       // First item of popup can't be routed to.
627 			}
628 			state.DoUpdate(this, TRUE);   // Popups are never auto disabled.
629 		}
630 		else
631 		{
632 			// Normal menu item.
633 			// Auto enable/disable if frame window has m_bAutoMenuEnable
634 			// set and command is _not_ a system command.
635 			state.m_pSubMenu = NULL;
636 			state.DoUpdate(this, FALSE);
637 		}
638 
639 		// Adjust for menu deletions and additions.
640 		UINT nCount = pPopupMenu->GetMenuItemCount();
641 		if (nCount < state.m_nIndexMax)
642 		{
643 			state.m_nIndex -= (state.m_nIndexMax - nCount);
644 			while (state.m_nIndex < nCount &&
645 				pPopupMenu->GetMenuItemID(state.m_nIndex) == state.m_nID)
646 			{
647 				state.m_nIndex++;
648 			}
649 		}
650 		state.m_nIndexMax = nCount;
651 	}
652 }
653 
654 
PositionButtons()655 void CWCDriver3DDlg::PositionButtons()
656 {
657 	CRect Rect;
658 	CWnd * pB = GetDlgItem(IDC_BUTTON_GO);
659 	pB->GetWindowRect(&Rect);
660 	ScreenToClient(Rect);
661 	Rect.right += PictureRect.left - Rect.left;
662 	Rect.left = PictureRect.left;
663 	pB->MoveWindow(Rect,FALSE);
664 
665 	int right;
666 	/*
667 	right = Rect.right;
668 	pB = GetDlgItem(IDC_BUTTON_DATA_MANAGER);
669 	pB->GetWindowRect(&Rect);
670 	ScreenToClient(Rect);
671 	Rect.right += right + BUTTONS_OFFSET - Rect.left;
672 	Rect.left = right + BUTTONS_OFFSET;
673 	pB->MoveWindow(Rect,FALSE);
674 	*/
675 	/*
676 	right = Rect.right;
677 	pB = GetDlgItem(IDC_BUTTON_READ_TEXT);
678 	pB->GetWindowRect(&Rect);
679 	ScreenToClient(Rect);
680 	Rect.right += right + BUTTONS_OFFSET - Rect.left;
681 	Rect.left = right + BUTTONS_OFFSET;
682 	pB->MoveWindow(Rect,FALSE);
683 	*/
684 	/*
685 	right = Rect.right;
686 	pB = GetDlgItem(IDC_BUTTON_SAVE_CONFIG);
687 	pB->GetWindowRect(&Rect);
688 	ScreenToClient(Rect);
689 	Rect.right += right + BUTTONS_OFFSET - Rect.left;
690 	Rect.left = right + BUTTONS_OFFSET;
691 	pB->MoveWindow(Rect,FALSE);
692 	*/
693 
694 
695 	right = Rect.right;
696 	pB = GetDlgItem(IDC_BUTTON_GENERALOPTIONS);
697 	pB->GetWindowRect(&Rect);
698 	ScreenToClient(Rect);
699 	Rect.right += right + BUTTONS_OFFSET - Rect.left;
700 	Rect.left = right + BUTTONS_OFFSET;
701 	pB->MoveWindow(Rect,FALSE);
702 
703 	/*
704 	right = Rect.right;
705 	pB = GetDlgItem(IDC_CHECK_LIGHTING);
706 	pB->GetWindowRect(&Rect);
707 	ScreenToClient(Rect);
708 	Rect.right += right + BUTTONS_OFFSET - Rect.left;
709 	Rect.left = right + BUTTONS_OFFSET;
710 	pB->MoveWindow(Rect,FALSE);
711 	*/
712 }
713 
OnButtonGoMessage(WPARAM,LPARAM)714 LRESULT CWCDriver3DDlg::OnButtonGoMessage(WPARAM, LPARAM)
715 {
716 	OnButtonGo();
717 	return 0;
718 }
719 
720 
721 // OLD VERSION:
722 /*
723 LRESULT CWCDriver3DDlg::OnUpdateText(WPARAM, LPARAM)
724 {
725 	if(!DialogDataManager.RetrievingData())
726 	{
727 		UpdateData(FALSE);
728 
729 		//CEdit * pEdit = (CEdit*)GetDlgItem(IDC_EDIT_CONSOLE);
730 		//pEdit->SetSel(100000000,100000000,FALSE);
731 
732 		if(::IsWindow(dialogComputationOutput.m_hWnd))
733 		{
734 			dialogComputationOutput.UpdateText(m_ConsoleText);
735 		}
736 	}
737 	return 0;
738 }*/
739 
740 double global_last_printtext_time = 0;
GetWallClockTime()741 double GetWallClockTime()
742 {
743 	timeb tb;
744 	tb.time = 0;
745 	tb.millitm = 0;
746 	ftime(&tb);
747 	return (tb.time+(double)tb.millitm*0.001);
748 }
749 // NEW VERSION (AD) calls Append, ReplaceLastLine or Update(full)
OnUpdateText(WPARAM,LPARAM)750 LRESULT CWCDriver3DDlg::OnUpdateText(WPARAM, LPARAM)
751 {
752 	if(!DialogDataManager.RetrievingData())
753 	{
754 		MSG msg;
755 		while(::PeekMessage(&msg, m_hWnd, WM_UPDATE_TEXT, WM_UPDATE_TEXT, PM_REMOVE)); // remove all pending update text messages
756 
757 		UpdateData(FALSE);
758 
759 		if(::IsWindow(dialogComputationOutput.m_hWnd))
760 		{
761 			if(update_text_action_flag == 1)
762 			{
763 				dialogComputationOutput.AppendText(m_ConsoleText_append);
764 			}
765 			else if(update_text_action_flag == 2)
766 			{
767 				dialogComputationOutput.ReplaceLastLine(m_ConsoleText_append);
768 			}
769 			else if(update_text_action_flag == 0)
770 			{
771 				dialogComputationOutput.UpdateText(m_ConsoleText);
772 			}
773 			else
774 			{
775 				int maxlength = m_ConsoleText.GetLength();
776 
777 				if (pWCDI->GetIOption(152) != -1)
778 				{
779 					maxlength = min(pWCDI->GetIOption(152),maxlength);
780 					CString str = m_ConsoleText.Right(maxlength);
781 					dialogComputationOutput.UpdateText(str);
782 				}
783 				else
784 				{
785 					dialogComputationOutput.UpdateText(m_ConsoleText);
786 				}
787 			}
788 /*
789 			global_last_printtext_time = GetWallClockTime();
790 			SetTextRefreshTimer(0);       // reset timer
791 // critical section - accessing variable with append_text
792 EnterCriticalSection(&uses_append_text);
793 			m_ConsoleText_buffer = m_ConsoleText_buffer.Mid(m_ConsoleText_append.GetLength());
794 			m_ConsoleText_append.Empty(); // delete append buffer after text was updated
795 LeaveCriticalSection(&uses_append_text);
796 */
797 		}
798 	}
799 	return 0;
800 }
801 
OnSysCommand(UINT nID,LPARAM lParam)802 void CWCDriver3DDlg::OnSysCommand(UINT nID, LPARAM lParam)
803 {
804 /*	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
805 	{
806 		CAboutDlg dlgAbout;
807 		dlgAbout.DoModal();
808 	}
809 	else*/
810 	{
811 		CDialog::OnSysCommand(nID, lParam);
812 	}
813 }
814 
815 // If you add a minimize button to your dialog, you will need the code below
816 //  to draw the icon.  For MFC applications using the document/view model,
817 //  this is automatically done for you by the framework.
818 
819 int hotint_startup_message_written = 0;
OnPaint()820 void CWCDriver3DDlg::OnPaint()
821 {
822 	if (IsIconic())
823 	{
824 		CPaintDC dc(this); // device context for painting
825 
826 		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
827 
828 		// Center icon in client rectangle
829 		int cxIcon = GetSystemMetrics(SM_CXICON);
830 		int cyIcon = GetSystemMetrics(SM_CYICON);
831 		CRect rect;
832 		GetClientRect(&rect);
833 		int x = (rect.Width() - cxIcon + 1) / 2;
834 		int y = (rect.Height() - cyIcon + 1) / 2;
835 
836 		// Draw the icon
837 		dc.DrawIcon(x, y, m_hIcon);
838 	}
839 	else
840 	{
841 		CDialog::OnPaint();
842 	}
843 
844 #ifdef HOTINT_PUBLIC_DOMAIN
845 	if (!hotint_startup_message_written && pWCDI->GetIOption(141))
846 	{
847 		CString message = "";
848 		message += "Welcome to HOTINT V0.900 beta!\n";
849 		message += "This is a beta version and not all features have been yet fully tested!\n";
850 		message += "While the programmer acted with high caution and a lot of verification has been\n";
851 		message += "done already, it is recommended to verify the results!\n";
852 		message += "This program is distributed in the hope that it will be useful,\n";
853 		message += "but WITHOUT ANY WARRANTY; without even the implied warranty of \n";
854 		message += "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE!\n\n";
855 
856 		message += "******   Bug reports and comments are welcome: jg@jku.at   ******";
857 
858 		AfxMessageBox(message);
859 	}
860 	hotint_startup_message_written = 1;
861 #endif
862 
863 }
864 
865 
866 // The system calls this to obtain the cursor to display while the user drags
867 //  the minimized window.
OnQueryDragIcon()868 HCURSOR CWCDriver3DDlg::OnQueryDragIcon()
869 {
870 	return (HCURSOR) m_hIcon;
871 }
872 
OnSize(UINT nType,int cx,int cy)873 void CWCDriver3DDlg::OnSize(UINT nType, int cx, int cy)
874 {
875 	if(cx != 0 && cy != 0)
876 	{
877 		int vertical_shift = PictureRect.bottom-cy;
878 
879 		PictureRect.right = cx;
880 		PictureRect.bottom = cy;
881 
882 		if(::IsWindow(GLDrawWnd.m_hWnd))
883 			GLDrawWnd.MoveWindow(PictureRect,FALSE);
884 
885 		/*
886 		CRect r;
887 
888 		CWnd * pEditConsole = GetDlgItem(IDC_EDIT_CONSOLE);
889 		if(pEditConsole)
890 		{
891 		pEditConsole->GetWindowRect(&r);
892 		ScreenToClient(&r);
893 		pEditConsole->MoveWindow(r.left,r.top,r.Width(),r.Height()-vertical_shift,FALSE);
894 		}
895 		*/
896 
897 		RedrawWindow();
898 	}
899 
900 	CDialog::OnSize(nType, cx, cy);
901 }
902 
903 
OnMove(int x,int y)904 void CWCDriver3DDlg::OnMove(int x, int y)
905 {
906 	if(::IsWindow(dialogComputationOutput.m_hWnd))
907 	{
908 		CRect r, rw;
909 		GetWindowRect(&rw);
910 		dialogComputationOutput.GetWindowRect(&r);
911 		dialogComputationOutput.MoveWindow(rw.left-r.Width(), rw.top, r.Width(), r.Height(), TRUE); //no Repaint
912 	}
913 
914 	__super::OnMove(x, y);
915 
916 	// TODO: F�gen Sie hier Ihren Meldungsbehandlungscode ein.
917 }
918 
919 
InstantMessageText(const char * pStr)920 void CWCDriver3DDlg::InstantMessageText(const char * pStr)
921 {
922 	AfxMessageBox(pStr);
923 }
924 
StatusText(const char * pStr)925 void CWCDriver3DDlg::StatusText(const char * pStr)
926 {
927 	CString text = CString("HOTINT");
928 	if (fileopened)
929 	{
930 		if (strlen(pWCDI->GetTOption(85)) != 0)
931 		{
932 			text += " - ";
933 			text += pWCDI->GetTOption(85);
934 		}
935 		else
936 		{
937 			text += "Multibody simulation code";
938 		}
939 	}
940 	int len = strlen(pStr);
941 	if (len != 0)	text = CString(pStr) + CString(" - ") + text;
942 
943 	char str[512];
944 	len = strlen(text);
945 
946 	if (len > 511) text.SetAt(511, (char)0);
947 	strcpy(str, text);
948 
949 	SendMessage(WM_SETTEXT,NULL,(LPARAM)str);
950 }
951 
DisplaySelectedModelName()952 void CWCDriver3DDlg::DisplaySelectedModelName()
953 {
954 // version: display in Main Window
955 	CString text = CString("HOTINT --- current Model: ") + CString(pWCDI->MBS_EDC_TreeGetString("GeneralOptions.ModelFile.internal_model_function_name"));
956 	this->SetWindowText(text);
957 
958 // version: display in Iconbar - disabled as of 2013-09-30
959 	//CString text = CString("Model: ") + CString(pWCDI->MBS_EDC_TreeGetString("GeneralOptions.ModelFile.internal_model_function_name"));
960 	//CEdit* eb = (CEdit*) GetDlgItem(IDC_EDIT_MODELNAME);
961 	//eb->SetWindowText(text);
962 }
963 
AddRecentFile(const char * filename)964 void CWCDriver3DDlg::AddRecentFile(const char * filename) 	//$ DR 2012-12-06 add "filename" to list of recent files and resort this list
965 {
966 
967 	TArrayDynamic<mystr> recent_files;
968 	for(int i=0; i<=4; i++)
969 	{
970 		recent_files.Add(pWCDI->GetTOption(113+i));
971 	}
972 
973 	int pos = recent_files.Find(filename);
974 	if(pos==1)
975 	{
976 		return;		// is already at first position
977 	}
978 	else		// put the actual file at first position and add the others in old order
979 	{
980 		pWCDI->SetTOption(113,filename);
981 		int j;
982 		for(int i=1; i<=4; i++)
983 		{
984 			j=i;
985 			if(pos==i) {j++;}	// if already in list
986 			pWCDI->SetTOption(113+i,recent_files(j));
987 		}
988 		ElementDataContainer edc;
989 		pWCDI->CallCompFunction(210, 0, 0, &edc);		//$ DR 2012-12-17 update EDC of MBS
990 	}
991 }
992 
AddText(const char * pStr)993 void CWCDriver3DDlg::AddText(const char * pStr)
994 {
995 	if (!enableOutputText) return;
996 
997 	update_text_action_flag = 3;
998 	const static char _EOL[] = {13,10}; //{13,13,10}
999 	const static CString EOL = _EOL;
1000 	const static char _CARRET[] = {13,10}; //{13,13,10}
1001 	const static CString CARRET = _CARRET;
1002 
1003 	CString str(pStr);
1004 	int nEOL = str.Find('\n',0);
1005 	while(nEOL != -1)
1006 	{
1007 		m_ConsoleText += str.Left(nEOL) + EOL;
1008 		str = str.Mid(nEOL+1);
1009 		nEOL = str.Find('\n',0);
1010 	}
1011 
1012 	nEOL = str.Find('\r',0);
1013 	if(nEOL != -1)
1014 	{
1015 		str = str.Mid(nEOL+1);
1016 		int off = 1;
1017 		int n = m_ConsoleText.Find((char)10, m_ConsoleText.GetLength()-off);
1018 		while ( n == -1 && off < m_ConsoleText.GetLength())
1019 		{
1020 			off += 1;
1021 			n = m_ConsoleText.Find((char)10, m_ConsoleText.GetLength()-off);
1022 		}
1023 
1024 		if (n != -1)
1025 		{
1026 			m_ConsoleText = m_ConsoleText.Left(n+1);
1027 		}
1028 	}
1029 	m_ConsoleText += str;
1030 
1031 	const double maxtime = 0;
1032 	double acttime = 0;
1033 	{
1034 		timeb tb;
1035 		tb.time = 0;
1036 		tb.millitm = 0;
1037 		ftime(&tb);
1038 		//cout << "time=" << tb.time << ", millisec=" << tb.millitm << endl;
1039 		acttime = tb.time+(double)tb.millitm*0.001;
1040 	}
1041 
1042 	if (acttime - global_last_printtext_time > maxtime)
1043 	{
1044 		SendMessage(WM_UPDATE_TEXT);		// we can not just call UpdateData(FALSE) due to multithreading
1045 	}
1046 	else
1047 	{
1048 		SendMessage(WM_UPDATE_TEXT);		// we can not just call UpdateData(FALSE) due to multithreading
1049 	}
1050 }
1051 
1052 // create directory (only, if it does not exist).
1053 // returns 0 in case of error (wrong path), 1 in case it already existed, and 2 if created
CreateMissingDirectory(const char * str)1054 int CWCDriver3DDlg::CreateMissingDirectory(const char * str)
1055 {
1056 	int rv = 2;
1057 
1058 	if (!CreateDirectory(str, NULL))
1059 	{
1060 		DWORD err = GetLastError();
1061 		if (err == ERROR_ALREADY_EXISTS)
1062 		{
1063 			rv = 1;
1064 		}
1065 		else   // err == ERROR_PATH_NOT_FOUND
1066 		{
1067 			rv = 0;
1068 		}
1069 	}
1070 	return rv;
1071 }
1072 
SetPlotToolRedrawTimer(int flag_onoff,int delay_ms)1073 void CWCDriver3DDlg::SetPlotToolRedrawTimer(int flag_onoff, int delay_ms)
1074 {
1075 	if (flag_onoff)
1076 	{
1077 		int suc = SetTimer(PLOTTOOL_REFRESH_TIMER_ID, (UINT) delay_ms, NULL);
1078 		if (!suc)
1079 			::MessageBox(this->GetSafeHwnd(),"Unable to start timer","PLOTTOOL_REFRESH_TIMER_ID",MB_OK|MB_SYSTEMMODAL);
1080 	}
1081 	else
1082 	{
1083 		KillTimer(PLOTTOOL_REFRESH_TIMER_ID);
1084 	}
1085 }
1086 
OnTimer(UINT_PTR nIDEvent)1087 void CWCDriver3DDlg::OnTimer(UINT_PTR nIDEvent)
1088 {
1089 	if (nIDEvent == PLOTTOOL_REFRESH_TIMER_ID)
1090 	{
1091 // check for pending PlotUpdateMessage
1092   	MSG msg;
1093 		if (::PeekMessageA(&msg, m_hWnd, WM_UPDATE_PLOT, WM_UPDATE_PLOT, 0))
1094 		{
1095 			SendMessage(WM_UPDATE_PLOT);
1096 		}
1097 	}
1098 
1099 	CWnd::OnTimer(nIDEvent);
1100 }
1101 
ResultsUpdated(int flag)1102 void CWCDriver3DDlg::ResultsUpdated(int flag)
1103 {
1104 	if (flag==1 || flag==0)
1105 		GLDrawWnd.SendMessage(WM_REDRAW);
1106 
1107 	if((flag==2 || flag==0)&& GetWCDInterface()->StoreResultsIsOn())
1108 	{
1109 		DataStorage ds; double m_TimePoint;
1110 		GetWCDInterface()->StoreResults(ds, m_TimePoint);
1111 		DialogDataManager.AddEntry(ds, m_TimePoint);
1112 
1113 		for (int i=0; i < MAX_SENSOR_WATCH; i++)
1114 		{
1115 			if (sensorwatchctrl[i])
1116 			{
1117 				if (::IsWindow(sensorwatchctrl[i]->m_hWnd))
1118 				{
1119 					ElementDataContainer edc;
1120 					pWCDI->CallCompFunction(204, 0, sensorwatchctrl[i]->GetSensorNumber(), &edc);
1121 					if (edc.Length() > 0)
1122 					{
1123 						double v = edc.Get(1).GetDouble();
1124 						char str[32];
1125 						sprintf_s(str, "%.17g",v);
1126 						sensorwatchctrl[i]->SetSensorText(str);
1127 					}
1128 				}
1129 			}
1130 		}
1131 	}
1132 }
1133 
OnLButtonDown(UINT nFlags,CPoint point)1134 void CWCDriver3DDlg::OnLButtonDown(UINT nFlags, CPoint point)
1135 {
1136 	CDialog::OnLButtonDown(nFlags, point);
1137 }
1138 
1139 
OnMouseMove(UINT nFlags,CPoint point)1140 void CWCDriver3DDlg::OnMouseMove(UINT nFlags, CPoint point)
1141 {
1142 
1143 	CDialog::OnMouseMove(nFlags, point);
1144 }
1145 
OnLButtonUp(UINT nFlags,CPoint point)1146 void CWCDriver3DDlg::OnLButtonUp(UINT nFlags, CPoint point)
1147 {
1148 	CDialog::OnLButtonUp(nFlags, point);
1149 }
1150 
1151 
OnMouseWheel(UINT nFlags,short zDelta,CPoint pt)1152 BOOL CWCDriver3DDlg::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
1153 {
1154 	GLDrawWnd.OnMouseWheelGLDW(nFlags, zDelta, pt); //windows function does not pass the message ...
1155 
1156 	return CDialog::OnMouseWheel(nFlags, zDelta, pt);
1157 }
1158 
1159 
ThreadControlFunc(LPVOID pVOID)1160 UINT ThreadControlFunc(LPVOID pVOID)
1161 {
1162 	CWCDriver3DDlg * pDlg = (CWCDriver3DDlg*)pVOID;
1163 	pDlg->GetWCDInterface()->Go(pDlg);
1164 
1165 	return 0;
1166 }
1167 /*
1168 //parallel threads work well for parallelism!!!
1169 int cnt;
1170 UINT ThreadControlFunc2(LPVOID pVOID)
1171 {
1172 CWCDriver3DDlg * pDlg = (CWCDriver3DDlg*)pVOID;
1173 //pDlg->GetWCDInterface()->Go(pDlg);
1174 
1175 double x=1;
1176 for (int i=1; i <= 100000; i++)
1177 {
1178 for (int j=1; j <= 1; j++)
1179 {
1180 x+=sin((i+j)/100000.);
1181 }
1182 }
1183 char str[200];
1184 sprintf_s(str, "ready: %g",x);
1185 //pDlg->AddText(str);
1186 cnt--;
1187 sprintf_s(str, "R%d %1.1f",cnt,(x+1.)/x);
1188 pDlg->GetDlgItem(IDC_BUTTON_GO)->SetWindowText(str);
1189 
1190 return 0;
1191 }
1192 */
1193 
OnButtonGo()1194 void CWCDriver3DDlg::OnButtonGo()
1195 {
1196 
1197 	if(!pWCDI->IsComputationInProgress())
1198 	{
1199 		GetDlgItem(IDC_BUTTON_GO)->SetWindowText("Stop");
1200 		//GetDlgItem(IDC_BUTTON_PAUSE)->SetForegroundWindow();
1201 		CWinThread * pWinThread  = AfxBeginThread(ThreadControlFunc,this);
1202 		SetThreadPriority(pWinThread->m_hThread,THREAD_PRIORITY_ABOVE_NORMAL);
1203 		//SetThreadPriority(pWinThread->m_hThread,THREAD_PRIORITY_BELOW_NORMAL);
1204 		/*
1205 		cnt = 1000;
1206 		for (int i=1; i <= 1000; i++)
1207 		{
1208 		CWinThread * pWinThread  = AfxBeginThread(ThreadControlFunc2,this);
1209 		SetThreadPriority(pWinThread->m_hThread,THREAD_PRIORITY_BELOW_NORMAL);
1210 		}*/
1211 	}
1212 	else
1213 	{
1214 		GetDlgItem(IDC_BUTTON_GO)->SetWindowText("Stopping..");
1215 		pWCDI->StopWhenPossible();
1216 	}
1217 }
1218 
FinishedComputation()1219 void CWCDriver3DDlg::FinishedComputation()
1220 {
1221 	GetDlgItem(IDC_BUTTON_GO)->SetWindowText("Restart");
1222 }
1223 
OnButtonPause()1224 void CWCDriver3DDlg::OnButtonPause()
1225 {
1226 	if (pWCDI->IsPaused())
1227 	{
1228 		//set scroll position to last time point
1229 		DialogDataManager.SetScrollPosToLastTimePoint();
1230 
1231 		//resume computation
1232 		GetDlgItem(IDC_BUTTON_GO)->EnableWindow(TRUE);
1233 		GetDlgItem(IDC_BUTTON_PAUSE)->SetWindowText("Pause");
1234 		pWCDI->Resume();
1235 	}
1236 	else
1237 	{
1238 		if (!pWCDI->IsComputationInProgress())
1239 			return;
1240 
1241 		//pause computation
1242 		pWCDI->Pause();
1243 		GetDlgItem(IDC_BUTTON_PAUSE)->EnableWindow(FALSE);
1244 		GetDlgItem(IDC_BUTTON_GO)->EnableWindow(FALSE);
1245 		GetDlgItem(IDC_BUTTON_PAUSE)->SetWindowText("Pausing..");
1246 	}
1247 }
1248 
PausedComputation()1249 void CWCDriver3DDlg::PausedComputation()
1250 {
1251 	GetDlgItem(IDC_BUTTON_PAUSE)->EnableWindow(TRUE);
1252 	GetDlgItem(IDC_BUTTON_PAUSE)->SetWindowText("Resume");
1253 }
1254 
SleepX(int xMilliseconds)1255 void CWCDriver3DDlg::SleepX(int xMilliseconds)
1256 {
1257 	Sleep(xMilliseconds);
1258 }
1259 
OnCancel()1260 void CWCDriver3DDlg::OnCancel()
1261 {
1262 #ifndef COMPILE_AND // AND: no questions whether to close or not
1263 	if(pWCDI->IsComputationInProgress())
1264 	{
1265 		if(AfxMessageBox("The computation is in progress.\nExit program?",MB_YESNO | MB_ICONQUESTION) == IDNO)
1266 			return;
1267 	}
1268 	else if (model_modified)
1269 	{
1270 		if(AfxMessageBox("The model has not been saved. All changes will be lost.\nExit program?",MB_YESNO | MB_ICONQUESTION) == IDNO)
1271 			return;
1272 	}
1273 	else
1274 	{
1275 		if(!bClosingDialog)
1276 			if(AfxMessageBox("Exit program?",MB_YESNO | MB_ICONQUESTION) == IDNO)
1277 				return;
1278 	}
1279 #endif // COMPILE_AND
1280 	CDialog::OnCancel();
1281 }
1282 
OnClose()1283 void CWCDriver3DDlg::OnClose()
1284 {
1285 	bClosingDialog = true;
1286 
1287 	CDialog::OnClose();
1288 }
1289 
1290 const int min_options_index = 100; //old: 1
1291 
1292 
ReadConfigFile()1293 void CWCDriver3DDlg::ReadConfigFile()
1294 {
1295 	//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1296 	ElementDataContainer edc;
1297 
1298 	//read EDC from config file:
1299 	int read_success =	pWCDI->CallCompFunction(106,0,0,&edc);
1300 
1301 	if(read_success)
1302 	{
1303 		if (edc.TreeFind("HOTINTConfiguration.HOTINTversion") != 0)
1304 		{
1305 			HotintVersionInfo config_version(edc.TreeGetDouble("HOTINTConfiguration.HOTINTversion",0.));
1306 
1307 			if (config_version == pWCDI->GetHotintVersion())
1308 			{
1309 				//write configuration parameters in WCDriver, GLDrawWnd
1310 				EDC2Configuration(edc);
1311 				return;
1312 			}
1313 			else
1314 			{
1315 				char str[512];
1316 				sprintf_s(str, "The HOTINT Version %s of the configuration file\nis different from the actual HOTINT Version %s\nand is therefore ignored!", config_version.GetString(), pWCDI->GetHotintVersion().GetString());
1317 #ifndef COMPILE_AND
1318 				AfxMessageBox(str);
1319 #endif
1320 			}
1321 		}
1322 	}
1323 
1324 	// do this, when there is no config-file or wrong version number
1325 	OnResultsViewoutput(); //$ DR 2013-02-26 added this line, to show output window
1326 	OnResultsDatamanager(); //$ DR 2013-02-27 added this line, to show data manager
1327 	return;
1328 
1329 }
1330 
Configuration2EDC(ElementDataContainer & edc)1331 void CWCDriver3DDlg::Configuration2EDC(ElementDataContainer& edc)
1332 {
1333 	edc.TreeSetDoubleC("HOTINTConfiguration.HOTINTversion", pWCDI->GetHotintVersion().GetDoubleValue(), "Version with which this file has been generated");
1334 	// first we write the positions of windows
1335 	CRect rect;
1336 	GetWindowRect(&rect);
1337 
1338 	edc.TreeSetIntC("HOTINTConfiguration.Application_Window.rect_left",rect.left,"left coordinate of application window");
1339 	edc.TreeSetIntC("HOTINTConfiguration.Application_Window.rect_top",rect.top,"top coordinate of application window");
1340 	edc.TreeSetIntC("HOTINTConfiguration.Application_Window.rect_width",rect.Width(),"width of application window");
1341 	edc.TreeSetIntC("HOTINTConfiguration.Application_Window.rect_height",rect.Height(),"left coordinate of application window");
1342 
1343 	// now the parameters of the OpenGL scene and of the frames recording
1344 	GLDrawWnd.Configuration2EDC(edc);
1345 
1346 
1347 	// and finally the state of the control windows
1348 	BOOL DataManagerWindowOpen = 0;
1349 	if(::IsWindow(DialogDataManager.m_hWnd))
1350 		DataManagerWindowOpen = 1;
1351 	edc.TreeSetBoolC("HOTINTConfiguration.data_manager_open",DataManagerWindowOpen,"open data manager on startup");
1352 
1353 	//ar << DialogDataManager.m_strDataRequest; //JG: not used anymore
1354 
1355 	BOOL OutputDialogOpen = 0;
1356 	int storedwidth = 200; //verify with outputdialog.cpp constructor!!!
1357 	if(::IsWindow(dialogComputationOutput.m_hWnd))
1358 	{
1359 		dialogComputationOutput.GetWindowRect(&rect);
1360 		storedwidth = rect.Width();
1361 		OutputDialogOpen = 1;
1362 	}
1363 	edc.TreeSetBoolC("HOTINTConfiguration.Output_dialog.dialog_open",OutputDialogOpen,"open output dialog on startup");
1364 	edc.TreeSetIntC("HOTINTConfiguration.Output_dialog.stored_width",storedwidth,"stored width of output dialog");
1365 	edc.TreeSetBoolC("HOTINTConfiguration.Output_dialog.enable_output_text",enableOutputText,"enable output text in output dialog");
1366 
1367 }
1368 
EDC2Configuration(const ElementDataContainer & edc)1369 void CWCDriver3DDlg::EDC2Configuration(const ElementDataContainer& edc)
1370 {
1371 	int left, top, width, height;
1372 	CRect rect;
1373 	GetWindowRect(&rect);
1374 
1375 	int left_default = 795;
1376 	int top_default = 595;
1377 	int width_default = 700;	//4000
1378 	int height_default = 700;	//4000
1379 
1380 	left = edc.TreeGetInt("HOTINTConfiguration.Application_Window.rect_left",left_default);
1381 	top = edc.TreeGetInt("HOTINTConfiguration.Application_Window.rect_top",top_default);
1382 	width = edc.TreeGetInt("HOTINTConfiguration.Application_Window.rect_width",width_default);
1383 	height = edc.TreeGetInt("HOTINTConfiguration.Application_Window.rect_height",height_default);
1384 
1385 	//$ DR 2013-03-27 removed setting to default screen
1386 	////change coordinates, if outside of standard screen 800x600!!!!
1387 	//if (left > left_default) left = left_default;
1388 	//if (top > top_default) top = top_default;
1389 	//if (width > width_default) width = width_default;
1390 	//if (height > height_default) height = height_default;
1391 
1392 	MoveWindow(left,top,width,height, TRUE);
1393 
1394 	GLDrawWnd.EDC2Configuration(edc);
1395 
1396 	BOOL DataManagerWindowOpen;
1397 	DataManagerWindowOpen = edc.TreeGetBool("HOTINTConfiguration.data_manager_open",1); //$ DR 2013-03-18 changed default to 1
1398 	DialogDataManager.m_strDataRequest = ""; //this will be erased in the future
1399 	// and finally the state of the control windows
1400 	if(DataManagerWindowOpen)
1401 		OnResultsDatamanager();
1402 
1403 
1404 	BOOL OutputDialogOpen;
1405 	OutputDialogOpen = edc.TreeGetBool("HOTINTConfiguration.Output_dialog.dialog_open",1);	//$ DR 2013-02-26 changed default to 1
1406 	dialogComputationOutput.storedwidth = edc.TreeGetInt("HOTINTConfiguration.Output_dialog.stored_width");
1407 	if(OutputDialogOpen)
1408 		OnResultsViewoutput();
1409 
1410 	enableOutputText = edc.TreeGetBool("HOTINTConfiguration.Output_dialog.enable_output_text");
1411 	enableOutputText = (enableOutputText+1)%2; //toggle 1.
1412 	OnResultsEnableoutput();									 //toggle 2. ==> original
1413 }
1414 
1415 
1416 
OnOptionsSaveconfiguration()1417 void CWCDriver3DDlg::OnOptionsSaveconfiguration()
1418 {
1419 	GLDrawWnd.SetProgramDirectoryAsCurrent();
1420 
1421 	//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1422 	ElementDataContainer edc;
1423 	//generate EDC data and pass to MBS
1424 	Configuration2EDC(edc);
1425 	pWCDI->CallCompFunction(107,0,0,&edc);
1426 	//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1427 
1428 
1429 	////old code, will be erased:
1430 	//CFile file;
1431 	//if(!file.Open(CONFIG_FILE_NAME,CFile::modeWrite | CFile::modeCreate))
1432 	//{
1433 	//	AfxMessageBox("Could not open the config file.", MB_ICONSTOP);
1434 	//	return;
1435 	//}
1436 
1437 	//CArchive ar(&file,CArchive::store);
1438 
1439 	//ar << HOTINT_version_info; //write the actual version of hotint!!!
1440 
1441 	//// first we write the positions of windows
1442 	//CRect rect;
1443 	//GetWindowRect(&rect);
1444 	//ar << (int)rect.left << (int)rect.top;
1445 	//ar << (int)rect.Width() << (int)rect.Height();
1446 	////GetDlgItem(IDC_EDIT_CONSOLE)->GetWindowRect(&rect);
1447 	////ar << rect.Width();
1448 
1449 	//// now the parameters of the OpenGL scene and of the frames recording
1450 	//GLDrawWnd.SaveConfig(ar);
1451 
1452 	////save options:
1453 	////computation:
1454 	//for (int i=001; i <= 300; i++)
1455 	//{
1456 	//	int val=0;
1457 	//	if (i < min_options_index) ar << val;
1458 	//	else ar << pWCDI->GetIOption(i);
1459 	//}
1460 	//for (int i=001; i <= 300; i++)
1461 	//{
1462 	//	if (i!=2) //exclude start time
1463 	//	{
1464 	//		double val=0.;
1465 	//		if (i < min_options_index) ar << val;
1466 	//		else ar << pWCDI->GetDOption(i);
1467 	//	}
1468 	//}
1469 	////Text options
1470 	//for (int i=1; i <= 300; i++)
1471 	//{
1472 	//	if (i < min_options_index || pWCDI->GetTOption(i) == 0)
1473 	//		ar << CString("");
1474 	//	else
1475 	//		ar << CString(pWCDI->GetTOption(i));
1476 	//}
1477  //
1478 
1479 	//// and finally the state of the control windows
1480 	//BOOL DataManagerWindowOpen = 0;
1481 	//if(::IsWindow(DialogDataManager.m_hWnd))
1482 	//	DataManagerWindowOpen = 1;
1483 	//ar << DataManagerWindowOpen;
1484 	//ar << DialogDataManager.m_strDataRequest;
1485 
1486 	//BOOL OutputDialogOpen = 0;
1487 	//int storedwidth = 200; //verify with outputdialog.cpp constructor!!!
1488 	//if(::IsWindow(dialogComputationOutput.m_hWnd))
1489 	//{
1490 	//	dialogComputationOutput.GetWindowRect(&rect);
1491 	//	storedwidth = rect.Width();
1492 	//	OutputDialogOpen = 1;
1493 	//}
1494 	//ar << storedwidth;
1495 	//ar << OutputDialogOpen;
1496 
1497 	//ar << enableOutputText;
1498 
1499 }
1500 
OnEditEditsolveroptions()1501 void CWCDriver3DDlg::OnEditEditsolveroptions()
1502 {
1503 	CTreeViewCustomEditDialog ced;
1504 	ced.SetWCDI(pWCDI);
1505 	ced.SetGLDrawWnd(&GLDrawWnd);
1506 	ElementDataContainer edc_solveroptions;
1507 	pWCDI->CallCompFunction(210,0,1,&edc_solveroptions); // call with value == 1 for solver options only
1508 
1509 	ced.SetDialogName("Edit Solver Options");
1510 	ced.SetElementDataContainer(&edc_solveroptions);
1511 	ced.SetUseApply(1, 210, 1, 1);		// these are the codes of the functions for various actions available in the dialog
1512 	ced.DoModal();
1513 }
1514 
OnOptionsSaveSolverOptions()1515 void CWCDriver3DDlg::OnOptionsSaveSolverOptions()
1516 {
1517 	GLDrawWnd.SetProgramDirectoryAsCurrent();
1518 
1519 	//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1520 	ElementDataContainer edc;
1521 	//generate EDC data and pass to MBS
1522 	Configuration2EDC(edc);
1523 	pWCDI->CallCompFunction(107,0,1,&edc); // call with value == 1
1524 	//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1525 }
1526 
OnEditEdithotintoptions()1527 void CWCDriver3DDlg::OnEditEdithotintoptions()
1528 {
1529 	CTreeViewCustomEditDialog ced;
1530 	ced.SetWCDI(pWCDI);
1531 	ced.SetGLDrawWnd(&GLDrawWnd);
1532 	ElementDataContainer edc_hotintoptions;
1533 	pWCDI->CallCompFunction(210,0,2,&edc_hotintoptions); // call with value == 2 for hotint options only
1534 
1535 	ced.SetDialogName("Edit Hotint Options");
1536 	ced.SetElementDataContainer(&edc_hotintoptions);
1537 	ced.SetUseApply(1, 210, 1, 2);		// these are the codes of the functions for various actions available in the dialog
1538 	ced.DoModal();
1539 }
1540 
OnOptionsSaveHotintOptions()1541 void CWCDriver3DDlg::OnOptionsSaveHotintOptions()
1542 {
1543 	GLDrawWnd.SetProgramDirectoryAsCurrent();
1544 
1545 	//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1546 	ElementDataContainer edc;
1547 	//generate EDC data and pass to MBS
1548 	Configuration2EDC(edc);
1549 	pWCDI->CallCompFunction(107,0,2,&edc); // call with value == 2
1550 	//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1551 }
1552 
OnFileExit()1553 void CWCDriver3DDlg::OnFileExit()
1554 {
1555 	OnCancel();
1556 }
1557 
OnHelpAbout()1558 void CWCDriver3DDlg::OnHelpAbout()
1559 {
1560 	CAboutDlg dlgAbout;
1561 	dlgAbout.SetpWCDI(pWCDI);
1562 	dlgAbout.DoModal();
1563 }
1564 
1565 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1566 
CallWCDriverFunction(int action,int option,int value,ElementDataContainer * edc)1567 int CWCDriver3DDlg::CallWCDriverFunction(int action, int option, int value, ElementDataContainer* edc)
1568 {
1569 	//action=1: redraw
1570 	//action=2: Edit loads of element 'value', load number 'option'
1571 
1572 	int rv = 1;
1573 	//insert actions performed by WCDriver on call by MBS-System
1574 
1575 	switch(action)
1576 	{
1577 	case 1: //Redraw
1578 		{
1579 			GLDrawWnd.SendMessage(WM_REDRAW);
1580 			Dialog2DView.ForceUpdate();
1581 			//AD: Added update options and redraw all PlotTool Windows
1582 			for (int i=1; i<= PlotToolArray.Length(); i++)
1583 			{
1584 				if(option==0) PlotToolArray(i)->Redraw();
1585 				if(option==1) PlotToolArray(i)->UpdateDialogData();
1586 			}
1587 			break;
1588 		}
1589 	case 2: //Edit Dialog for load
1590 		{
1591 			rv = 0; //ok, nothing to delete
1592 
1593 			ElementDataContainer edc;
1594 			int nelem = value;
1595 			int loadnum = option;
1596 			pWCDI->GetElementData(nelem, 2, loadnum, edc); //type==2 --> element load
1597 			CustomEditDialog ced; ced.SetWCDI(pWCDI); ced.SetGLDrawWnd(&GLDrawWnd);
1598 
1599 			ced.SetDialogName("Edit load");
1600 
1601 			ced.SetDeleteButton(1);
1602 
1603 			ced.SetElementDataContainer(&edc);
1604 			if (ced.DoModal() != IDCANCEL)
1605 			{
1606 				//write data to element;
1607 				pWCDI->SetElementData(nelem, 2, loadnum, edc); //type2==load
1608 			}
1609 			else
1610 			{
1611 				if (ced.GetDeleteFlag())
1612 				{
1613 					pWCDI->CallCompFunction(5, loadnum, nelem);
1614 					//inform calling function that force is deleted (not needed)
1615 					rv = ced.GetDeleteFlag();
1616 				}
1617 				else
1618 				{
1619 					rv = 0;
1620 				}
1621 			}
1622 
1623 			break;
1624 		}
1625 	case 3: //Open File Requester for STL
1626 		{
1627 			static char BASED_CODE szFilter[] = "STL file (*.stl)|*.stl|All Files (*.*)|*.*||";
1628 
1629 			CFileDialog fd(TRUE,"mbs",0,OFN_OVERWRITEPROMPT|OFN_ENABLESIZING|OFN_FILEMUSTEXIST ,szFilter); //true=load, false=save
1630 			if(fd.DoModal() == IDCANCEL)
1631 			{
1632 				rv = 0;
1633 			}
1634 			else
1635 			{
1636 				edc->Reset();
1637 				ElementData ed;
1638 				ed.SetText(fd.GetPathName(), "PathName");
1639 				edc->Add(ed);
1640 			}
1641 			break;
1642 		}
1643 	case 4: //Set Program directory as current
1644 		{
1645 			GLDrawWnd.SetProgramDirectoryAsCurrent();
1646 			break;
1647 		}
1648 	case 5: // Quit Program from MBS
1649 		{
1650 			CDialog::OnCancel();
1651 			break;
1652 		}
1653 	case 6: //reset model
1654 		{
1655 			ModelChanged();
1656 			break;
1657 		}
1658 	case 7: // close Eigenvalue computation window
1659 		{
1660 			if (::IsWindow(computeEigenmodes.m_hWnd)) computeEigenmodes.SendMessage(WM_CLOSE_EV_WINDOW);
1661 			break;
1662 		}
1663 	case 8: // open sensorwatch for sensor "value" (PlotTool)
1664 		{
1665 			if (value>0)
1666 			{
1667 				CPlotToolDlg* activeplottool;
1668 				int nr = GetPlotToolDlg(activeplottool,-1); // sensor always opens a new plottool ?
1669 				CRect viewrect = ComputeDisplayRectForSensorWatch(nr);
1670 				activeplottool->InitializeWithSensorTY(value, viewrect);
1671 			}
1672 			break;
1673 		}
1674 	case 9: // close all PlotTool instances
1675 		{
1676 			for (int i=1; i<= PlotToolArray.Length(); i++)
1677 				PlotToolArray(i)->ExternClose();
1678 			PlotToolArray.Flush();
1679 			break;
1680 		}
1681 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1682 //Progress Bar
1683 //action=10: activate ProgressBar, options := (0)hide, (1)show, (2)set total ticks, (3)set actual ticks, (4)change status text, (5)pos/size
1684 	case 10:
1685 		{
1686 			if (!::IsWindow(dialogProgressbar.m_hWnd) && !(option==1)) return 0; // no window and not "show" operation
1687 
1688 			switch(option)
1689 			{
1690 			case 0:
1691 //				if(::IsWindow(dialogProgressbar.m_hWnd))
1692 					dialogProgressbar.ShowWindow(SW_HIDE);
1693 				break;
1694 
1695 			case 1:
1696 				if(!::IsWindow(dialogProgressbar.m_hWnd))
1697 				{
1698 					dialogProgressbar.Create(IDD_DIALOG_PROGRESSBAR,this);
1699 					dialogProgressbar.Reset();
1700 				}
1701 				else
1702 					dialogProgressbar.ShowWindow(SW_SHOW);
1703 				break;
1704 
1705 			case 2:
1706 //				if(::IsWindow(dialogProgressbar.m_hWnd))
1707 					dialogProgressbar.SetTotalTicks(value);
1708 				break;
1709 			case 3:
1710 //				if(::IsWindow(dialogProgressbar.m_hWnd))
1711 					dialogProgressbar.SetActualTicks(value);
1712 				break;
1713 			case 4:
1714 	//			if(::IsWindow(dialogProgressbar.m_hWnd))
1715 				{
1716 					mystr caption = edc->TreeGetString("Caption");
1717 					mystr over = edc->TreeGetString("Over");
1718 					mystr under = edc->TreeGetString("Under");
1719 
1720 					if (caption.Length()) dialogProgressbar.SetCaptionText(caption);
1721 					if (over.Length()) dialogProgressbar.SetTextOver(over);
1722 					if (under.Length()) dialogProgressbar.SetTextUnder(under);
1723 				}
1724 				break;
1725 //			case 5: break;
1726 			default: assert(0); break;
1727 			}
1728 			break;
1729 		}
1730 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1731 //Copy data (loaded from external file) to DataManager (e.g. Eigenmodes,...)
1732 //action = 20, option:= number of vectors to store (e.g. number of eigenmodes), edc:= contains the vectors (entries "SV#" & "DV#")
1733 	case 20:
1734 		{
1735 // (AD) under construction
1736 			if(!::IsWindow(DialogDataManager.m_hWnd))
1737 				DialogDataManager.Create(this);
1738 
1739 			DialogDataManager.RemoveAll(); // clear DialogDataManager
1740 
1741 
1742       double* solvec = NULL;
1743 			double* datavec = NULL;
1744 			int n_sol, n_data;
1745 
1746 			for(int j=1; j<=option; j++)
1747 			{
1748 // entries for i'th solution vector
1749 				edc->TreeGetVector(mystr("SV")+mystr(j), &solvec, n_sol);
1750 // entries for i'th data vector
1751 				edc->TreeGetVector(mystr("DV")+mystr(j), &datavec, n_data);
1752 
1753 				DataStorage storage;
1754 				WCDInterface::DataSaver& ds = storage; // must be cast to DataSaver to write data !!!
1755 				ds.SetTime(j);
1756 // solution vector
1757 				ds << n_sol;
1758 				for (int i=0; i<n_sol; i++)
1759 				{
1760 					ds << solvec[i];
1761 				}
1762 // data vector
1763 				ds << n_data;
1764 				for (int i=0; i<n_data; i++)
1765 				{
1766 					ds << datavec[i];
1767 				}
1768 
1769 				DialogDataManager.AddEntry(storage, j);
1770 			}
1771 			break;
1772 		}
1773 	default: ;
1774 	}
1775 	return rv;
1776 }
1777 
OnBnClickedButtonSaveMbs()1778 void CWCDriver3DDlg::OnBnClickedButtonSaveMbs()
1779 {
1780 	OnFileSavembs();
1781 }
1782 
OnFileSavembs()1783 void CWCDriver3DDlg::OnFileSavembs()
1784 {
1785 	mystr filename = pWCDI->MBS_EDC_TreeGetString("GeneralOptions.ModelFile.hotint_input_data_filename");
1786 
1787 	if (filename.Compare(""))
1788 	{
1789 		OnFileSavembsas();
1790 	}
1791 	else
1792 	{
1793 		int pos = filename.Find(".hmc");
1794 		int l = filename.Length();
1795 		if(pos == l-4)
1796 		{
1797 			ElementDataContainer edc;
1798 			ElementData ed;
1799 			ed.SetText(filename, "File_name"); edc.Add(ed);
1800 			ed.SetText("", "Directory_name"); edc.Add(ed);
1801 
1802 			pWCDI->CallCompFunction(101, 1, 0, &edc); //no return value, should always work!
1803 
1804 			SetModelModified(0);
1805 			AddRecentFile(filename);
1806 		}
1807 		else
1808 		{
1809 			OnFileSavembsas();
1810 		}
1811 	}
1812 }
1813 
OnFileSavembsas()1814 void CWCDriver3DDlg::OnFileSavembsas()
1815 {
1816 	mystr path = pWCDI->MBS_EDC_TreeGetString("GeneralOptions.Paths.application_path");
1817 	static char BASED_CODE szFilter[] = "HMC file (*.hmc)|*.hmc|";
1818 	CFileDialog fd(FALSE,"mbs",0,OFN_HIDEREADONLY|OFN_ENABLESIZING|OFN_OVERWRITEPROMPT,szFilter); //true=load, false=save
1819 	if(fd.DoModal() == IDCANCEL)
1820 	{
1821 		SetCurrentDirectory(path);	//$ DR 2012-12-06 reset path to old path
1822 		return;
1823 	}
1824 	SetCurrentDirectory(path);	//$ DR 2012-12-06 reset path to old path
1825 
1826 	if(fd.GetFileExt().Compare("hmc"))
1827 	{
1828 		AfxMessageBox("It is just possible to save *.hmc files!");
1829 		return;
1830 	}
1831 
1832 	CString pathname = fd.GetPathName();
1833 
1834 	if (strlen(fd.GetFileName()) != 0)
1835 	{
1836 	  //CMenu* mmenu = GetMenu();
1837 		//mmenu->ModifyMenu(ID_FILE_RECENTFILE1, MF_BYCOMMAND, ID_FILE_RECENTFILE1, CString("&Recent: ")+CString(pWCDI->GetTOption(94)));
1838 		//mmenu->EnableMenuItem(ID_FILE_RECENTFILE1, MF_BYCOMMAND | MF_ENABLED); //MF_DISABLED | MF_GRAYED
1839 
1840 		ElementDataContainer edc;
1841 		ElementData ed;
1842 		ed.SetText(pathname, "File_name"); edc.Add(ed);
1843 		ed.SetText("", "Directory_name"); edc.Add(ed);
1844 
1845 		pWCDI->CallCompFunction(101, 1, 0, &edc); //no return value, should always work!
1846 
1847 		pWCDI->SetTOption(110, pathname);
1848 		pWCDI->MBS_EDC_TreeSetString(pathname,"GeneralOptions.ModelFile.hotint_input_data_filename");
1849 
1850 		CString filename = fd.GetFileName();
1851 		pWCDI->SetTOption(112,filename);
1852 		pWCDI->MBS_EDC_TreeSetString(filename,"GeneralOptions.Paths.internal_model_function_name");
1853 
1854 		SetModelModified(0);
1855 		AddRecentFile(pathname);
1856 	}
1857 }
1858 
AutoSavembs()1859 void CWCDriver3DDlg::AutoSavembs()
1860 {
1861 	ElementDataContainer edc;
1862 	ElementData ed;
1863 	mystr path = pWCDI->MBS_EDC_TreeGetString("GeneralOptions.Paths.application_path");
1864 
1865 	int activate = 0;
1866 	pWCDI->MBS_EDC_TreeGetInt(activate,"GeneralOptions.Application.activate_autosave");
1867 	if(activate)
1868 	{
1869 		if(asv_models.Length())
1870 		{
1871 			if(asv_models.Right(1).MakeInt() == MAX_AUTOSAVE_MODELS)
1872 			{
1873 				asv_models += mystr(1);
1874 			}
1875 			else
1876 			{
1877 				asv_models += mystr(asv_models.Right(1).MakeInt()+1);
1878 			}
1879 
1880 			if(asv_models.Length() > MAX_AUTOSAVE_MODELS)
1881 			{
1882 				asv_models.EraseChar(1);
1883 			}
1884 		}
1885 		else
1886 		{
1887 			asv_models = "1";
1888 		}
1889 		mystr asv_model_name = "model_asv_" + asv_models.Right(1) + ".hmc";
1890 		//ed.SetText("model_asv.hmc", "File_name");  edc.Add(ed);
1891 		ed.SetText(asv_model_name, "File_name");  edc.Add(ed);
1892 		ed.SetText(path, "Directory_name"); edc.Add(ed);
1893 
1894 		pWCDI->CallCompFunction(101, 0, 0, &edc); //no return value, should always work!
1895 	}
1896 }
1897 
OnFileOpenmbs()1898 void CWCDriver3DDlg::OnFileOpenmbs()
1899 {
1900 	if(pWCDI->IsComputationInProgress())
1901 	{
1902 		AfxMessageBox("Computation is running, file can not be loaded!");
1903 		return;
1904 	}
1905 
1906 	if(pWCDI->GetNElements() != 0 && !(AfxMessageBox("Discard all body information?",MB_YESNO | MB_ICONQUESTION) == IDYES))
1907 	{
1908 		return;
1909 	}
1910 
1911 	mystr path = pWCDI->MBS_EDC_TreeGetString("GeneralOptions.Paths.application_path");
1912 	//static char BASED_CODE szFilter[] = "HMC and HID files (*.hmc)|*.hmc|HID file (*.hid)|*.hid|All Files (*.*)|*.*||";
1913 	static char BASED_CODE szFilter[] = "HMC and HID files (*.hmc;*.hid)|*.hmc; *.hid|All Files (*.*)|*.*||";
1914 	CFileDialog fd(TRUE,"mbs",0,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ENABLESIZING|OFN_FILEMUSTEXIST ,szFilter); //true=load, false=save
1915 	if(fd.DoModal() == IDCANCEL)
1916 	{
1917 		SetCurrentDirectory(path);	//$ DR 2012-12-06 reset path to old path
1918 		return;
1919 	}
1920 	SetCurrentDirectory(path);	//$ DR 2012-12-06 reset path to old path
1921 
1922 	GLDrawWnd.prohibit_redraw = 1;
1923 
1924 	CString pathname = fd.GetPathName();
1925 	CString filename = fd.GetFileName();
1926 
1927 	ElementDataContainer edc; ElementData ed;
1928 	ed.SetText(pathname, "File_name"); edc.Add(ed);
1929 	ed.SetText("", "Directory_name"); edc.Add(ed);
1930 
1931 
1932 	pWCDI->SetTOption(110, pathname);
1933 	pWCDI->MBS_EDC_TreeSetString(pathname,"GeneralOptions.ModelFile.hotint_input_data_filename");
1934 	pWCDI->SetModelData_Initialized(0);
1935 	pWCDI->CallCompFunction(1, 1, 0, &edc);				// Initialize MBS
1936 
1937 	AddRecentFile(pathname);
1938 	pWCDI->SetTOption(112,filename);
1939 	pWCDI->MBS_EDC_TreeSetString(filename,"GeneralOptions.Paths.internal_model_function_name");
1940 
1941 	pWCDI->CallCompFunction(210, 0, 0, &edc);		//$ DR 2012-12-06 update EDC of MBS
1942 	ModelChanged();
1943 }
1944 
1945 
1946 
OnEditUndo()1947 void CWCDriver3DDlg::OnEditUndo()
1948 {
1949 	if(pWCDI->IsComputationInProgress())
1950 	{
1951 		AfxMessageBox("Computation is running, file can not be loaded!");
1952 		return;
1953 	}
1954 
1955 	mystr pathname = pWCDI->MBS_EDC_TreeGetString("GeneralOptions.Paths.application_path");
1956 
1957 	if(asv_models.Length())
1958 	{
1959 		pathname += "model_asv_";
1960 		pathname +=	asv_models.Right(1);
1961 		pathname += ".hmc";
1962 		asv_models.SetLength(asv_models.Length()-1);
1963 
1964 		ElementDataContainer edc; ElementData ed;
1965 		ed.SetText(pathname, "File_name"); edc.Add(ed);
1966 		ed.SetText("", "Directory_name"); edc.Add(ed);
1967 
1968 		pWCDI->SetTOption(110, pathname);
1969 		pWCDI->MBS_EDC_TreeSetString(pathname,"GeneralOptions.ModelFile.hotint_input_data_filename");
1970 		pWCDI->SetModelData_Initialized(0);
1971 		pWCDI->CallCompFunction(1, 1, 0, &edc);				// Initialize MBS
1972 
1973 		ModelChanged();
1974 	}
1975 	else
1976 	{
1977 		AfxMessageBox("No autosaved model available.");
1978 		return;
1979 	}
1980 }
1981 
1982 
OnFileRecentfile1()1983 void CWCDriver3DDlg::OnFileRecentfile1()
1984 {
1985 	//return; //$ DR 2012-12-07 not implemented yet
1986 
1987 	if(pWCDI->IsComputationInProgress())
1988 	{
1989 		AfxMessageBox("Computation is running, MBS can not be loaded!");
1990 		return;
1991 	}
1992 
1993 	mystr filename = 	pWCDI->GetTOption(113);
1994 	//mystr filename = pWCDI->MBS_EDC_TreeGetString("GeneralOptions.ModelFile.recent_file1");
1995 
1996 	if (filename.Find(":")>0)		//it is a file to load
1997 	{
1998 		ElementDataContainer edc; ElementData ed;
1999 		ed.SetText(filename, "File_name"); edc.Add(ed);
2000 		ed.SetText("", "Directory_name"); edc.Add(ed);
2001 
2002 		pWCDI->SetTOption(110, filename);
2003 		pWCDI->MBS_EDC_TreeSetString(filename,"GeneralOptions.ModelFile.hotint_input_data_filename");
2004 		pWCDI->SetModelData_Initialized(0);
2005 		pWCDI->CallCompFunction(1, 1, 0, &edc);				// Initialize MBS
2006 
2007 		pWCDI->CallCompFunction(210, 0, 0, &edc);		// update EDC of MBS
2008 		ModelChanged();
2009 	}
2010 	else	// internal model
2011 	{
2012 		ElementDataContainer edc;
2013 		pWCDI->CallCompFunction(20,1,0,&edc); //edc contains model function names
2014 
2015 		int found = 0;
2016 		mystr model = "";
2017 		//found = edc.Find(filename); // not working
2018 
2019 		for(int i=1; i<=edc.Length(); i++)
2020 		{
2021 			mystr model = edc.Get(i).GetText();
2022 			if(model.Compare(filename))
2023 			{
2024 				found = i;
2025 				i = edc.Length()+1; // to break for loop
2026 			}
2027 		}
2028 
2029 		if (found)
2030 		{
2031 			pWCDI->MBS_EDC_TreeSetString(filename, "GeneralOptions.ModelFile.internal_model_function_name");
2032 			pWCDI->MBS_EDC_TreeSetString("","GeneralOptions.ModelFile.hotint_input_data_filename");
2033 
2034 			pWCDI->CallCompFunction(20,2); //tell MBS that model function has been changed!
2035 			ModelChanged();
2036 		}
2037 		else
2038 		{
2039 			AfxMessageBox("The specified internal model is not available anymore!");
2040 			return;
2041 		}
2042 	}
2043 }
2044 
2045 
2046 
OnBnClickedButtonRecentFile()2047 void CWCDriver3DDlg::OnBnClickedButtonRecentFile()
2048 {
2049 	OnFileRecentfile1();
2050 }
2051 
2052 
OnComputationLoadinitialvector()2053 void CWCDriver3DDlg::OnComputationLoadinitialvector()
2054 {
2055 	if(pWCDI->IsComputationInProgress())
2056 	{
2057 		AfxMessageBox("Computation is running!\nInitial vector can not be loaded.");
2058 		return;
2059 	}
2060 
2061 	static char BASED_CODE szFilter[] = "MBS file (*.sol)|*.sol|All Files (*.*)|*.*||";
2062 
2063 	CFileDialog fd(TRUE,"mbs",0,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ENABLESIZING|OFN_FILEMUSTEXIST ,szFilter); //true=load, false=save
2064 
2065 	if(fd.DoModal() == IDCANCEL) {return;}
2066 
2067 	CString pathname = fd.GetPathName();
2068 	int plen = fd.GetPathName().GetLength(); //dir+filename
2069 	int flen = fd.GetFileName().GetLength(); //filename
2070 	CString dirname = pathname.Left(plen-flen);
2071 
2072 	ElementDataContainer edc; ElementData ed;
2073 	ed.SetText(fd.GetFileName(), "File_name"); edc.Add(ed);
2074 	ed.SetText(dirname, "Directory_name"); edc.Add(ed);
2075 
2076 	int modified = GetModelModified();
2077 	ModelChanged();
2078 	SetModelModified(modified);
2079 
2080 	if (!pWCDI->CallCompFunction(104, 0, 0, &edc))
2081 	{
2082 		AfxMessageBox("Error: Initial vector could not be loaded!");
2083 		return;
2084 	}
2085 	pWCDI->CallCompFunction(1); //Set initial conditions
2086 
2087 	GLDrawWnd.ContentsChanged(); //fit on screen and redraw
2088 }
2089 
OnComputationStoresolutionvector()2090 void CWCDriver3DDlg::OnComputationStoresolutionvector()
2091 {
2092 	if(pWCDI->IsComputationInProgress())
2093 	{
2094 		AfxMessageBox("Computation is running!\nSolution can not be stored.");
2095 		return;
2096 	}
2097 
2098 	static char BASED_CODE szFilter[] = "MBS file (*.sol)|*.sol|All Files (*.*)|*.*||";
2099 
2100 	CFileDialog fd(FALSE,"mbs",0,OFN_HIDEREADONLY|OFN_ENABLESIZING|OFN_OVERWRITEPROMPT,szFilter); //true=load, false=save
2101 	if(fd.DoModal() == IDCANCEL) {return;}
2102 
2103 
2104 	CString pathname = fd.GetPathName();
2105 	int plen = fd.GetPathName().GetLength(); //dir+filename
2106 	int flen = fd.GetFileName().GetLength(); //filename
2107 	CString dirname = pathname.Left(plen-flen);
2108 
2109 	ElementDataContainer edc; ElementData ed;
2110 	ed.SetText(fd.GetFileName(), "File_name"); edc.Add(ed);
2111 	ed.SetText(dirname, "Directory_name"); edc.Add(ed);
2112 
2113 	if (!pWCDI->CallCompFunction(103, 0, 0, &edc))
2114 	{
2115 		AfxMessageBox("Error: Initial vector could not be saved!");
2116 		return;
2117 	}
2118 
2119 }
2120 
2121 
2122 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2123 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2124 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2125 //Computation:
2126 
OnResultsDatamanager()2127 void CWCDriver3DDlg::OnResultsDatamanager()
2128 {
2129 	if(!::IsWindow(DialogDataManager.m_hWnd))
2130 	{
2131 		DialogDataManager.Create(this);
2132 	}
2133 	else
2134 	{
2135 		DialogDataManager.CheckScreenLocation(); //check that data manager is not outside screen
2136 	}
2137 }
2138 
OnViewShowContolWindow()2139 void CWCDriver3DDlg::OnViewShowContolWindow()
2140 {
2141 	if(!::IsWindow(Dialog2DView.m_hWnd))
2142 	{
2143 		Dialog2DView.Create(IDD_DIALOG_2D_VIEW,this);
2144 		Dialog2DView.ShowWindow(SW_SHOW);
2145 	}
2146 	else
2147 	{
2148 		Dialog2DView.ShowWindow(SW_SHOW);
2149 		Dialog2DView.CheckScreenLocation();
2150 	}
2151 }
2152 
2153 
OnResultsViewoutput()2154 void CWCDriver3DDlg::OnResultsViewoutput()
2155 {
2156 	if(!::IsWindow(dialogComputationOutput.m_hWnd))
2157 	{
2158 		dialogComputationOutput.Create(this);
2159 		dialogComputationOutput.UpdateText(m_ConsoleText);
2160 	}
2161 }
2162 
2163 
OnComputationReset()2164 void CWCDriver3DDlg::OnComputationReset()
2165 {
2166 	if(!pWCDI->IsComputationInProgress())
2167 	{
2168 		pWCDI->CallCompFunction(1); //Set initial conditions //$ DR 2013-10-11 not in ModelChanged anymore
2169 		ModelChanged();
2170 	}
2171 	this->AddText("Computation reset\n");
2172 }
2173 
OnComputationPrinttimings()2174 void CWCDriver3DDlg::OnComputationPrinttimings()
2175 {
2176 	if(!pWCDI->IsComputationInProgress())
2177 	{
2178 		pWCDI->PrintTimingList();
2179 	}
2180 }
2181 
OnResultsShowoutputstatictext()2182 void CWCDriver3DDlg::OnResultsShowoutputstatictext()
2183 {
2184 	CDialogReadText drt;
2185 	drt.m_Text = m_ConsoleText;
2186 	drt.DoModal();
2187 }
2188 
OnResultsEnableoutput()2189 void CWCDriver3DDlg::OnResultsEnableoutput()
2190 {
2191 	enableOutputText = (enableOutputText+1)%2;
2192 
2193 	if (enableOutputText) GetMenu()->CheckMenuItem(ID_RESULTS_ENABLEOUTPUT, MF_CHECKED);
2194 	else GetMenu()->CheckMenuItem(ID_RESULTS_ENABLEOUTPUT, MF_UNCHECKED);
2195 
2196 }
2197 
2198 
2199 //void CWCDriver3DDlg::OnComputationAssemblesystem()
2200 //{
2201 //	if(!pWCDI->IsComputationInProgress())
2202 //	{
2203 //		pWCDI->CallCompFunction(3);
2204 //		GLDrawWnd.ContentsChanged(); //fit on screen and redraw	}
2205 //	}
2206 //}
2207 
OnSystemShowsystemproperties()2208 void CWCDriver3DDlg::OnSystemShowsystemproperties()
2209 {
2210 	pWCDI->CallCompFunction(301);
2211 }
2212 
2213 
OnSystemChecksystem()2214 void CWCDriver3DDlg::OnSystemChecksystem()
2215 {
2216 	if (pWCDI->CallCompFunction(302))
2217 	{
2218 		AfxMessageBox("The system shows inconsistencies! See the output window and\ncheck the element, constraint, sensor and GeomElement numbers!");
2219 	}
2220 }
2221 
2222 
2223 //void CWCDriver3DDlg::OnComputationAssigninitialvector()
2224 //{
2225 //	if(!pWCDI->IsComputationInProgress())
2226 //	{
2227 //		pWCDI->CallCompFunction(1);
2228 //		GLDrawWnd.ContentsChanged(); //fit on screen and redraw
2229 //	}
2230 //}
2231 
OnFileNewmbs()2232 void CWCDriver3DDlg::OnFileNewmbs()
2233 {
2234 	if(!pWCDI->IsComputationInProgress())
2235 	{
2236 		if(AfxMessageBox("Discard all body information?",MB_YESNO | MB_ICONQUESTION) == IDYES)
2237 		{
2238 			pWCDI->SetTOption(112, "new model");
2239 			pWCDI->MBS_EDC_TreeSetString("new model", "GeneralOptions.ModelFile.internal_model_function_name");
2240 
2241 			pWCDI->SetTOption(110, "");
2242 			pWCDI->MBS_EDC_TreeSetString("", "GeneralOptions.ModelFile.hotint_input_data_filename");
2243 
2244 			SetModelModified();
2245 			pWCDI->CallCompFunction(20,2); //tell MBS that model function has been changed!
2246 
2247 			pWCDI->SetTOption(112, "new model");
2248 			pWCDI->MBS_EDC_TreeSetString("new model", "GeneralOptions.ModelFile.internal_model_function_name"); // not working yet
2249 
2250 			ModelChanged();
2251 			this->AddText("MBS System reset");
2252 		}
2253 	}
2254 	else
2255 	{
2256 		AfxMessageBox("Computation is running, system can not be reset!");
2257 	}
2258 }
2259 
OnResultsPlotsensor()2260 void CWCDriver3DDlg::OnResultsPlotsensor()
2261 {
2262 	CustomListDialog list;
2263 	list.SetPixelSize(200,400);
2264 
2265 	ElementDataContainer edc;
2266 	pWCDI->CallCompFunction(203,0,0,&edc); //edc contains sensor names
2267 
2268 	for (int i=1; i <= edc.Length(); i++)
2269 	{
2270 		char str[16];
2271 		sprintf_s(str,"%d-", i);
2272 		list.AddString(CString(str)+CString(edc.Get(i).GetDataName()), i);
2273 	}
2274 
2275 	list.SetUseEditItem(1);
2276 	list.InitList("Select sensor", "Select sensor to plot:");
2277 	list.DoModal();
2278 
2279 	if (list.item_selected)
2280 	{
2281 		//$ RL 2011-6-9: [ define is replaced by hotint-option now.
2282 		int use_plottool;
2283 		pWCDI->MBS_EDC_TreeGetInt(use_plottool, "PlotToolOptions.activate");
2284 		if(use_plottool)
2285 		{
2286 			CPlotToolDlg* activeplottool;
2287 			int nr = GetPlotToolDlg(activeplottool,-1); // sensor always opens a new plottool ?
2288 			CRect viewrect = ComputeDisplayRectForSensorWatch(nr);
2289 			activeplottool->InitializeWithSensorTY(list.item_selected, viewrect); //CRect(800,150,1100,350));
2290 		}
2291 		else
2292 		{
2293 			if (!pWCDI->CallCompFunction(121,0,list.item_selected)) //action=121: plot sensor 'list.item_selected'
2294 			{
2295 				AfxMessageBox("Warning: Sensor does not contain own solution file and therefore can not be plotted!");
2296 			}
2297 		}
2298 		//$ RL 2011-6-9: ]
2299 	}
2300 }
2301 
OnResultsPlot2sensorsxy()2302 void CWCDriver3DDlg::OnResultsPlot2sensorsxy()
2303 {
2304 	CustomListDialog list;
2305 	list.SetPixelSize(200,400);
2306 
2307 	ElementDataContainer edc;
2308 	pWCDI->CallCompFunction(203,0,0,&edc); //edc contains sensor names
2309 
2310 	for (int i=1; i <= edc.Length(); i++)
2311 	{
2312 		char str[16];
2313 		sprintf_s(str,"%d-", i);
2314 		list.AddString(CString(str)+CString(edc.Get(i).GetDataName()), i);
2315 	}
2316 
2317 	ElementDataContainer plotedc;
2318 
2319 	list.SetUseEditItem(1);
2320 	list.InitList("XY-Plot Select sensor X", "Select sensor to plot:");
2321 	list.DoModal();
2322 
2323 	if (list.item_selected)
2324 	{
2325 		int xsens_nr = list.item_selected;
2326 
2327 		list.SetUseEditItem(1);
2328 		list.InitList("XYPlot Select sensor Y", "Select sensor to plot:");
2329 		list.DoModal();
2330 
2331 		if (list.item_selected)
2332 		{
2333 			int ysens_nr = list.item_selected;
2334 
2335 			int use_plottool;
2336 			pWCDI->MBS_EDC_TreeGetInt(use_plottool, "PlotToolOptions.activate");
2337 			if(use_plottool)
2338 			{
2339 				CPlotToolDlg* activeplottool;
2340 				int nr = GetPlotToolDlg(activeplottool,-1); // sensor always opens a new plottool ?
2341 				CRect viewrect = ComputeDisplayRectForSensorWatch(nr);
2342 
2343 				activeplottool->InitializeWithSensorXY(xsens_nr, ysens_nr, CRect(800,150,1100,350));
2344 			}
2345 			else
2346 			{
2347 				plotedc.TreeSetInt("xsensor",list.item_selected);
2348 				plotedc.TreeSetInt("ysensor",list.item_selected);
2349 				if (!pWCDI->CallCompFunction(122,0,0,&plotedc)) //plot two sensors 'edc.xsensor' vs 'edc.ysensor'  in matlab
2350 				{
2351 					AfxMessageBox("Warning: Sensor does not contain own solution file and therefore can not be plotted!");
2352 				}
2353 			}
2354 		}
2355 	}
2356 }
2357 
2358 ////old code (used before PlotTool)
2359 //void CWCDriver3DDlg::OnResultsPlotnsensors()
2360 //{
2361 //	CustomListDialog list;
2362 //	list.SetPixelSize(200,400);
2363 //  //list.SetUseEditItem(LBS_MULTIPLESEL);
2364 //	ElementDataContainer edc;
2365 //	pWCDI->CallCompFunction(203,0,0,&edc); //edc contains sensor names
2366 //
2367 //	for (int i=1; i <= edc.Length(); i++)
2368 //	{
2369 //		char str[16];
2370 //		sprintf_s(str,"%d-", i);
2371 //		list.AddString(CString(str)+CString(edc.Get(i).GetDataName()), i);
2372 //	}
2373 //
2374 //	ElementDataContainer plotedc;
2375 //
2376 //	list.SetUseEditItem(1);
2377 //	list.InitList("Time-Plot Select sensor Y1", "Select sensor to plot:");
2378 //
2379 //	list.DoModal();
2380 //
2381 //	int count = 1;
2382 //	while(list.item_selected)
2383 //	{
2384 //		plotedc.TreeSetInt("y" + mystr(count)+ "sensor",list.item_selected);
2385 //		count++;
2386 //		list.SetUseEditItem(1);
2387 //		list.InitList("Time-Plot Select sensor Y" + mystr(count), "Select sensor to plot:");
2388 //		list.DoModal();
2389 //	}
2390 //	if(!pWCDI->CallCompFunction(123,count-1,0,&plotedc)) //time plot of N sensors in matlab
2391 //	{
2392 //		AfxMessageBox("Warning: Sensor does not contain own solution file and therefore can not be plotted!");
2393 //	}
2394 //}
2395 
ComputeDisplayRectForSensorWatch(int i)2396 CRect CWCDriver3DDlg::ComputeDisplayRectForSensorWatch(int i)
2397 {
2398 	CRect desktop;
2399 	GetDesktopWindow()->GetWindowRect(desktop);
2400 
2401 	int totalheight = desktop.Height();
2402 	int totalwidth = desktop.Width();
2403 
2404 	int viewheight;
2405 	int viewwidth;
2406 	pWCDI->MBS_EDC_TreeGetInt(viewheight,"PlotToolOptions.Watches.initial_size_vertical");
2407 	pWCDI->MBS_EDC_TreeGetInt(viewwidth,"PlotToolOptions.Watches.initial_size_horizontal");
2408 
2409 
2410 	double factor_x = 1.1;  // hard coded factor for border,...
2411 	double factor_y = 1.15; // hard coded factor for border,...
2412 
2413 	int spots_x = (int) floor ((double)totalwidth / (viewwidth*factor_x));
2414 	int spots_y = (int) floor ((double)totalheight / (viewheight*factor_y));
2415 
2416 // position of window 1
2417 	int p0x = totalwidth - (int) (viewwidth*(factor_x+1.)*0.5 +0.5);
2418 	int p0y =  (int) (viewheight*(factor_y-1.) +0.5);
2419 
2420 
2421 	int shift_y = (i-1)%spots_y;
2422 	int shift_x = ((i-1)%(spots_x*spots_y)) / spots_y;
2423 	int shift_z = (i-1) / (spots_x*spots_y);
2424 
2425 	p0y = p0y + (int) (shift_y*viewheight*factor_y + 0.5);
2426 	p0x = p0x - (int) (shift_x*viewwidth*factor_x + 0.5);
2427 
2428 	p0x = p0x + (int) (shift_z*viewwidth*factor_x/5. +0.5);
2429 	p0y = p0y + (int) (shift_y*viewheight*factor_y/5. + 0.5);
2430 
2431 // place views such that
2432 	CRect view(p0x, p0y, p0x+viewwidth, p0y+viewheight);
2433 	return view;
2434 }
2435 
GetSensorWatchDialog(CDialogOneEditControl * & watch,int & dialognum)2436 void CWCDriver3DDlg::GetSensorWatchDialog(CDialogOneEditControl*& watch, int& dialognum)
2437 {
2438 	for (int i=0; i < MAX_SENSOR_WATCH; i++)
2439 	{
2440 		if (!sensorwatchctrl[i])
2441 		{
2442 			sensorwatchctrl[i] = new CDialogOneEditControl();
2443 			watch = sensorwatchctrl[i];
2444 			dialognum = i;
2445 			return;
2446 		}
2447 		else if (!::IsWindow(sensorwatchctrl[i]->m_hWnd))
2448 		{
2449 			watch = sensorwatchctrl[i];
2450 			dialognum = i;
2451 			return;
2452 		}
2453 	}
2454 	dialognum = 0;
2455 	watch = 0;
2456 	return;
2457 }
2458 
OnResultsSensorwatch()2459 void CWCDriver3DDlg::OnResultsSensorwatch()
2460 {
2461 	CustomListDialog list;
2462 	list.SetPixelSize(200,400);
2463 
2464 	ElementDataContainer edc;
2465 	pWCDI->CallCompFunction(203,0,0,&edc); //edc contains sensor names
2466 
2467 	for (int i=1; i <= edc.Length(); i++)
2468 	{
2469 		char str[32];
2470 		sprintf_s(str,"%d-", i);
2471 		list.AddString(CString(str)+CString(edc.Get(i).GetDataName()), i);
2472 	}
2473 
2474 	list.SetUseEditItem(1);
2475 
2476 	list.InitList("Select sensor", "Select sensor to watch:");
2477 
2478 	list.DoModal();
2479 
2480 	if (list.item_selected)
2481 	{
2482 		CDialogOneEditControl* cwatch;
2483 		int dialognum;
2484 		GetSensorWatchDialog(cwatch, dialognum);
2485 
2486 		if (cwatch)
2487 		{
2488 			char str[32];
2489 			sprintf_s(str, "%d: '", list.item_selected);
2490 			CString name = CString("Sensor ")+CString(str)+CString(edc.Get(list.item_selected).GetDataName())+CString("'");
2491 			cwatch->InitWatch(name, list.item_selected, dialognum);
2492 			cwatch->SetWCDI(pWCDI);
2493 			cwatch->Create(this);
2494 		}
2495 		else
2496 		{
2497 			AfxMessageBox("Sorry, too many sensor watches opened!");
2498 		}
2499 	}
2500 }
2501 
2502 
2503 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2504 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2505 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2506 //Options:
2507 
OnBnClickedButtonGeneraloptions()2508 void CWCDriver3DDlg::OnBnClickedButtonGeneraloptions()
2509 {
2510 	OnViewViewingoptions();
2511 
2512 	/*
2513 	if(!::IsWindow(DialogFEDrawingOptions.m_hWnd))
2514 	DialogFEDrawingOptions.Create(this);*/
2515 
2516 }
2517 
OnViewRigidbodyJointOptions()2518 void CWCDriver3DDlg::OnViewRigidbodyJointOptions()
2519 {
2520 	if(!::IsWindow(dialogBodyJointOptions.m_hWnd))
2521 		dialogBodyJointOptions.Create(this);
2522 }
2523 
OnViewFeDrawingoptions()2524 void CWCDriver3DDlg::OnViewFeDrawingoptions()
2525 {
2526 	if(!::IsWindow(DialogFEDrawingOptions.m_hWnd))
2527 		DialogFEDrawingOptions.Create(this);
2528 }
2529 
OnViewViewingoptions()2530 void CWCDriver3DDlg::OnViewViewingoptions()
2531 {
2532 	if(!::IsWindow(dialogViewingOptions.m_hWnd))
2533 		dialogViewingOptions.Create(this);
2534 }
2535 
2536 //void CWCDriver3DDlg::OnComputationComputationoptions()		//$ DR 2013-10-16 removed
2537 //{
2538 //	if(!::IsWindow(dialogComputationSettings.m_hWnd))
2539 //		dialogComputationSettings.Create(this);
2540 //}
2541 
OnComputationComputeEigenmodes()2542 void CWCDriver3DDlg::OnComputationComputeEigenmodes()
2543 {
2544 	if(!::IsWindow(computeEigenmodes.m_hWnd))
2545 		computeEigenmodes.Create(this);
2546 }
2547 
OnViewOpengloptions()2548 void CWCDriver3DDlg::OnViewOpengloptions()
2549 {
2550 	if(!::IsWindow(dialogOpenGLOptions.m_hWnd))
2551 		dialogOpenGLOptions.Create(this);
2552 }
2553 
2554 
2555 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2556 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2557 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ModelChanged()2558 void CWCDriver3DDlg::ModelChanged()
2559 {
2560 	SetModelModified();
2561 	pWCDI->CallCompFunction(105); //Clear stored initial vector
2562 
2563 	//pWCDI->SetDOption2, 0.);
2564 	pWCDI->MBS_EDC_TreeSetDouble(0.,"SolverOptions.start_time"); //reset start time, otherwise nothing is computed the second time
2565 	DialogDataManager.RemoveAll(); //remove stored output
2566 	//pWCDI->CallCompFunction(3); //Assemble //$ 2013-02-04 not necessary?
2567 	//pWCDI->CallCompFunction(1); //Set initial conditions //$ 2013-02-04 not necessary?
2568 	//int rv = pWCDI->CallCompFunction(302); //Check Consistency //$ DR 2012-12-04 added
2569 	//if(rv < 2)
2570 	//{
2571 	GLDrawWnd.prohibit_redraw = 0;
2572 	GLDrawWnd.ContentsChanged(0); //fit on screen and redraw
2573 	Dialog2DView.ForceUpdate(); //$ DR 2013-03-18 redraw 2D window
2574 	//}
2575 	StatusText(""); //set new status text according to file name, remove finished
2576 	DisplaySelectedModelName();		//$ DR 2012-12-06 added
2577 }
2578 
2579 
2580 //Add/Edit elements:
2581 
2582 //option&1 Edit/Add element
2583 //option&4 Edit/Add load
2584 //option&8 Edit/Add sensor
2585 //option&16 Edit/Add GeomElement
2586 //option&32 Edit/Add Node
2587 //option&64 Edit/Add Material
2588 //option&2 Add instead of edit
2589 //option&256 edit Robot options menu (old)
2590 
EditElementProperties(int nelem,int option)2591 int CWCDriver3DDlg::EditElementProperties(int nelem, int option)
2592 {
2593 	CTreeViewCustomEditDialog ced;  //$JG:2012-1-22: view element properties in tree view
2594 	//CustomEditDialog ced;
2595 	ced.SetWCDI(pWCDI); ced.SetGLDrawWnd(&GLDrawWnd);
2596 	ElementDataContainer edc;
2597 	if (option&1)
2598 	{
2599 		pWCDI->GetElementData(nelem, 1, 0, edc); //type=1->element, type=2->load, type=3->Sensor
2600 		if (option&2)
2601 			ced.SetDialogName("Add element");
2602 		else
2603 			ced.SetDialogName("Edit element");
2604 	}
2605 	else if (option&4)
2606 	{
2607 		pWCDI->GetElementData(nelem, 2, 0, edc); //type=1->element, type=2->load, type=3->Sensor
2608 		if (option&2)
2609 			ced.SetDialogName("Add Load");
2610 		else
2611 			ced.SetDialogName("Edit Load");
2612 	}
2613 	else if (option&8)
2614 	{
2615 		pWCDI->GetElementData(nelem, 3, 0, edc); //type=1->element, type=2->load, type=3->Sensor
2616 		if (option&2)
2617 			ced.SetDialogName("Add Sensor");
2618 		else
2619 			ced.SetDialogName("Edit Sensor");
2620 	}
2621 	else if (option&16)
2622 	{
2623 		pWCDI->GetElementData(nelem, 4, 0, edc); //type=1->element, type=2->load, type=3->Sensor, type=4->Sensor
2624 		if (option&2)
2625 			ced.SetDialogName("Add Geometric Element");
2626 		else
2627 			ced.SetDialogName("Edit Geometric Element");
2628 	}
2629 	else if (option&32)
2630 	{
2631 		pWCDI->GetElementData(nelem, 5, 0, edc); //type=1->element, type=2->load, type=3->Sensor, type=4->Sensor, type=5->Node
2632 		if (option&2)
2633 			ced.SetDialogName("Add Node");
2634 		else
2635 			ced.SetDialogName("Edit Node");
2636 	}
2637 	else if (option&64) //material
2638 	{
2639 		pWCDI->GetElementData(nelem, 6, 0, edc); //type=1->element, type=2->load, type=3->Sensor, type=4->Sensor, type=5->Node, type=6->Material
2640 		if (option&2)
2641 			ced.SetDialogName("Add Material");
2642 		else
2643 			ced.SetDialogName("Edit Material");
2644 	}
2645 	else if (option&256)
2646 	{
2647 		pWCDI->GetElementData(nelem, 50, 0, edc); //type=50->Robot options menu (old)
2648 		ced.SetDialogName("Edit Robot options");
2649 	}
2650 	else
2651 	{
2652 		ced.SetDialogName("Edit");
2653 	}
2654 
2655 	ElementDataContainer edc_root; //in order to show root entries
2656 	ElementData root;
2657 	const char* rt = "root";
2658 	root.SetEDC(&edc, rt);
2659 	edc_root.Add(root);
2660 
2661 	ElementData* edr = edc_root.TreeFind(rt);
2662 	//const ElementDataContainer& edcnew = *edr->GetEDC();
2663 	ElementDataContainer& edcnew = *edr->GetEDC();
2664 
2665 	//ced.SetElementDataContainer(&edc);
2666 	ced.SetElementDataContainer(&edc_root);
2667 
2668 	int rv = 1;
2669 	if (ced.DoModal() != IDCANCEL)
2670 	{
2671 		if (!(option&2))		// autosave before editing object. For saving before ADDING objects, AutoSave is called directly in these functions
2672 		{
2673 			AutoSavembs();	//$ DR 2013-03-19
2674 		}
2675 		SetModelModified();
2676 		if (option&1)
2677 		{
2678 			//write data to element;
2679 			rv = pWCDI->SetElementData(nelem, 1, 0, edcnew); //type 1==element data
2680 		}
2681 		else if (option&4)	//$ DR 2012-10
2682 		{
2683 			//write data to load;
2684 			rv = pWCDI->SetElementData(nelem, 2, 0, edcnew); //type 2==load data
2685 		}
2686 		else if (option&8)
2687 		{
2688 			//write data to sensor;
2689 			rv = pWCDI->SetElementData(nelem, 3, 0, edcnew); //type 3==sensor data
2690 		}
2691 		else if (option&16)
2692 		{
2693 			//write data to geomelement;
2694 			rv = pWCDI->SetElementData(nelem, 4, 0, edcnew); //type 4==geomelement data
2695 		}
2696 		else if (option&32)
2697 		{
2698 			//write data to node;
2699 			rv = pWCDI->SetElementData(nelem, 5, 0, edcnew); //type 5==node data
2700 		}
2701 		else if (option&64)
2702 		{
2703 			//write data to material;
2704 			rv = pWCDI->SetElementData(nelem, 6, 0, edcnew); //type 6==material data
2705 		}
2706 		else if (option&256)
2707 		{
2708 			//write data to geomelement;
2709 			pWCDI->SetElementData(nelem, 50, 0, edcnew); //type 5==node data
2710 		}
2711 		return rv;
2712 	}
2713 	else
2714 	{
2715 		//delete element:
2716 		return 0;
2717 	}
2718 }
2719 
2720 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2721 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2722 // Add objects
2723 
OnSpecialAddbody()2724 void CWCDriver3DDlg::OnSpecialAddbody()
2725 {
2726 	if(pWCDI->IsComputationInProgress()) {AfxMessageBox("Computation is running! Operation not possible."); return;}
2727 
2728 	CustomListDialog list;
2729 
2730 	int nElements = pWCDI->GetObjectFactory()->GetAvailableTypesCount(OFCElement);
2731 	for (int i=1; i <= nElements; i++)
2732 	{
2733 		{
2734 			CString name = pWCDI->GetObjectFactory()->GetTypeName(OFCElement,i);
2735 			int typeflags = pWCDI->GetObjectFactory()->GetTypeFlags(OFCElement,i);
2736 
2737 			if( !(pWCDI->GetObjectFactory()->ExcludeExperimentalObjects()) || !(typeflags & TAENotInRelease) )
2738 			{
2739 				if(!(typeflags & TAEconstraint) && !(typeflags & TAEinput_output))
2740 				{
2741 						list.AddString(name, i);
2742 				}
2743 			}
2744 		}
2745 	}
2746 
2747 	//needs to be called at last:
2748 	list.InitList("Add body", "Select body type to be added:");
2749 	//add items to list:
2750 
2751 	list.DoModal();
2752 
2753 	if (list.item_selected)
2754 	{
2755 		AutoSavembs();	//$ DR 2013-03-19
2756 		int nelem = pWCDI->GetObjectFactory()->AddObject(OFCElement, list.item_selected);
2757 
2758 		if (nelem>0)
2759 		{
2760 			if (EditElementProperties(nelem,3))
2761 			{
2762 				//pWCDI->SetModelData_Initialized(0);						//$ DR 2013-02-04
2763 				pWCDI->CallCompFunction(3);										// Assemble				//$ DR 2013-10-11 not in ModelChanged anymore
2764 				pWCDI->CallCompFunction(1);										// SetInitialConditions //$ DR 2013-10-11 not in ModelChanged anymore
2765 				ModelChanged();																//$ DR 2013-02-04
2766 			}
2767 			else
2768 			{
2769 				//delete element:
2770 				pWCDI->CallCompFunction(4,0,nelem);
2771 			}
2772 		}
2773 		else
2774 		{
2775 			if (nelem == -1) AfxMessageBox("Error: Selected element type does not exist!!!\n");
2776 		}
2777 	}
2778 }
2779 
2780 
OnAddconnectorKinematicpairs()2781 void CWCDriver3DDlg::OnAddconnectorKinematicpairs()
2782 {
2783 	if(pWCDI->IsComputationInProgress()) {AfxMessageBox("Computation is running! Operation not possible."); return;}
2784 
2785 	CustomListDialog list;
2786 
2787 	int nElements = pWCDI->GetObjectFactory()->GetAvailableTypesCount(OFCElement);
2788 	for (int i=1; i <= nElements; i++)
2789 	{
2790 		{
2791 			CString name = pWCDI->GetObjectFactory()->GetTypeName(OFCElement,i);
2792 			int typeflags = pWCDI->GetObjectFactory()->GetTypeFlags(OFCElement,i);
2793 
2794 			if( !(pWCDI->GetObjectFactory()->ExcludeExperimentalObjects()) || !(typeflags & TAENotInRelease) )
2795 			{
2796 				if(typeflags & TAEconstraint)
2797 				{
2798 					list.AddString(name, i);
2799 				}
2800 			}
2801 		}
2802 	}
2803 
2804 	//needs to be called at last:
2805 	list.InitList("Add Connector", "Select connector type to be added:");
2806 	//add items to list:
2807 
2808 	list.DoModal();
2809 
2810 	if (list.item_selected)
2811 	{
2812 		AutoSavembs();	//$ DR 2013-03-19
2813 		int nelem = pWCDI->GetObjectFactory()->AddObject(OFCElement, list.item_selected);
2814 
2815 		if (nelem>0)
2816 		{
2817 			if (EditElementProperties(nelem,3))
2818 			{
2819 				//pWCDI->SetModelData_Initialized(0);						//$ DR 2013-02-04
2820 				pWCDI->CallCompFunction(3);										// Assemble				//$ DR 2013-10-11 not in ModelChanged anymore
2821 				pWCDI->CallCompFunction(1);										// SetInitialConditions //$ DR 2013-10-11 not in ModelChanged anymore
2822 				ModelChanged();																//$ DR 2013-02-04
2823 			}
2824 			else
2825 			{
2826 				//delete element:
2827 				pWCDI->CallCompFunction(4,0,nelem);
2828 			}
2829 		}
2830 		else
2831 		{
2832 			if (nelem == -1) AfxMessageBox("Error: Selected connector type does not exist!!!\n");
2833 		}
2834 	}
2835 }
2836 
OnAddconnectorControlelement()2837 void CWCDriver3DDlg::OnAddconnectorControlelement()
2838 {
2839 	if(pWCDI->IsComputationInProgress()) {AfxMessageBox("Computation is running! Operation not possible."); return;}
2840 
2841 	CustomListDialog list;
2842 	int nElements = pWCDI->GetObjectFactory()->GetAvailableTypesCount(OFCElement);
2843 	for (int i=1; i <= nElements; i++)
2844 	{
2845 		{
2846 			CString name = pWCDI->GetObjectFactory()->GetTypeName(OFCElement,i);
2847 			int typeflags = pWCDI->GetObjectFactory()->GetTypeFlags(OFCElement,i);
2848 
2849 			if( !(pWCDI->GetObjectFactory()->ExcludeExperimentalObjects()) || !(typeflags & TAENotInRelease) )
2850 			{
2851 				if(typeflags & TAEinput_output)
2852 				{
2853 					list.AddString(name, i);
2854 				}
2855 			}
2856 		}
2857 	}
2858 
2859 	//needs to be called at last:
2860 	list.InitList("Add Connector", "Select connector type to be added:");
2861 	//add items to list:
2862 
2863 	list.DoModal();
2864 
2865 	if (list.item_selected)
2866 	{
2867 		AutoSavembs();	//$ DR 2013-03-19
2868 		int nelem = pWCDI->GetObjectFactory()->AddObject(OFCElement, list.item_selected);
2869 
2870 		if (nelem>0)
2871 		{
2872 			if (EditElementProperties(nelem,3))
2873 			{
2874 				//pWCDI->SetModelData_Initialized(0);						//$ DR 2013-02-04
2875 				pWCDI->CallCompFunction(3);										// Assemble				//$ DR 2013-10-11 not in ModelChanged anymore
2876 				pWCDI->CallCompFunction(1);										// SetInitialConditions //$ DR 2013-10-11 not in ModelChanged anymore
2877 				ModelChanged();																//$ DR 2013-02-04
2878 			}
2879 			else
2880 			{
2881 				//delete element:
2882 				pWCDI->CallCompFunction(4,0,nelem);
2883 			}
2884 		}
2885 		else
2886 		{
2887 			if (nelem == -1) AfxMessageBox("Error: Selected connector type does not exist!!!\n");
2888 		}
2889 	}
2890 }
2891 
2892 
OnAddobjectAddnode()2893 void CWCDriver3DDlg::OnAddobjectAddnode()
2894 {
2895 	if(pWCDI->IsComputationInProgress()) {AfxMessageBox("Computation is running! Operation not possible."); return;}
2896 
2897 	// create list for choosing the sensor-type
2898 	CustomListDialog list;
2899 	int nNodes = pWCDI->GetObjectFactory()->GetAvailableTypesCount(OFCNode);
2900 	for (int i=1; i <= nNodes; i++)
2901 	{
2902 		CString name = pWCDI->GetObjectFactory()->GetTypeName(OFCNode,i);
2903 		int typeflags = pWCDI->GetObjectFactory()->GetTypeFlags(OFCNode,i);
2904 		if( !(pWCDI->GetObjectFactory()->ExcludeExperimentalObjects()) || !(typeflags & TAENotInRelease) )
2905 		{
2906 			list.AddString(name, i);
2907 		}
2908 	}
2909 
2910 	//needs to be called at last:
2911 	list.InitList("Add node", "Select node to be added:");
2912 
2913 	//add items to list:
2914 	list.DoModal();
2915 
2916 	if (list.item_selected)
2917 	{
2918 		AutoSavembs();	//$ DR 2013-03-19
2919 		int nnode = pWCDI->GetObjectFactory()->AddObject(OFCNode, list.item_selected);
2920 
2921 		if (nnode>0)
2922 		{
2923 			if (EditElementProperties(nnode,32+2)) //32==Edit node, 2==Add
2924 			{
2925 				//pWCDI->SetModelData_Initialized(0);						//$ DR 2013-02-04
2926 				pWCDI->CallCompFunction(3);										// Assemble				//$ DR 2013-10-11 not in ModelChanged anymore
2927 				pWCDI->CallCompFunction(1);										// SetInitialConditions //$ DR 2013-10-11 not in ModelChanged anymore
2928 				ModelChanged();																//$ DR 2013-02-04
2929 			}
2930 			else
2931 			{
2932 				//delete element:
2933 				pWCDI->CallCompFunction(12,0,nnode);
2934 			}
2935 		}
2936 		else
2937 		{
2938 			if (nnode == -1) AfxMessageBox("Error: Selected node type does not exist!!!\n");
2939 		}
2940 	}
2941 }
2942 
2943 
OnSpecialAddsensor()2944 void CWCDriver3DDlg::OnSpecialAddsensor()
2945 {
2946 	if(pWCDI->IsComputationInProgress()) {AfxMessageBox("Computation is running! Operation not possible."); return;}
2947 
2948 	// create list for choosing the sensor-type
2949 	CustomListDialog list;
2950 	int nSensors = pWCDI->GetObjectFactory()->GetAvailableTypesCount(OFCSensor);
2951 	for (int i=1; i <= nSensors; i++)
2952 	{
2953 		CString name = pWCDI->GetObjectFactory()->GetTypeName(OFCSensor,i);
2954 		int typeflags = pWCDI->GetObjectFactory()->GetTypeFlags(OFCSensor,i);
2955 		if( !(pWCDI->GetObjectFactory()->ExcludeExperimentalObjects()) || !(typeflags & TAENotInRelease) )
2956 		{
2957 			list.AddString(name, i);
2958 		}
2959 	}
2960 
2961 	//needs to be called at last:
2962 	list.InitList("Add sensor", "Select sensor to be added:");
2963 
2964 	//add items to list:
2965 	list.DoModal();
2966 
2967 	if (list.item_selected)
2968 	{
2969 		AutoSavembs();	//$ DR 2013-03-19
2970 		//int nsens = pWCDI->CallCompFunction(7,0,list.item_selected); //action=7: add sensor 'list.item_selected
2971 		int nsens = pWCDI->GetObjectFactory()->AddObject(OFCSensor, list.item_selected);
2972 
2973 		if (nsens>0)
2974 		{
2975 			if (EditElementProperties(nsens,8+2)) //8==Edit sensor, 2==Add
2976 			{
2977 				//pWCDI->SetModelData_Initialized(0);						//$ DR 2013-02-04
2978 				pWCDI->CallCompFunction(3);										// Assemble				//$ DR 2013-10-11 not in ModelChanged anymore
2979 				pWCDI->CallCompFunction(1);										// SetInitialConditions //$ DR 2013-10-11 not in ModelChanged anymore
2980 				ModelChanged();																//$ DR 2013-02-04
2981 			}
2982 			else
2983 			{
2984 				//delete element:
2985 				pWCDI->CallCompFunction(8,0,nsens);
2986 			}
2987 		}
2988 		else
2989 		{
2990 			if (nsens == -1) AfxMessageBox("Error: Selected sensor type does not exist!!!\n");
2991 		}
2992 	}
2993 }
2994 
2995 
OnSpecialAddgeomelement()2996 void CWCDriver3DDlg::OnSpecialAddgeomelement()
2997 {
2998 	if(pWCDI->IsComputationInProgress()) {AfxMessageBox("Computation is running! Operation not possible."); return;}
2999 
3000 	CustomListDialog list;
3001 	int nGeomElements = pWCDI->GetObjectFactory()->GetAvailableTypesCount(OFCGeomElement);
3002 	for (int i=1; i <= nGeomElements; i++)
3003 	{
3004 		CString name = pWCDI->GetObjectFactory()->GetTypeName(OFCGeomElement,i);
3005 		int typeflags = pWCDI->GetObjectFactory()->GetTypeFlags(OFCGeomElement,i);
3006 		if( !(pWCDI->GetObjectFactory()->ExcludeExperimentalObjects()) || !(typeflags & TAENotInRelease) )
3007 		{
3008 			list.AddString(name, i);
3009 		}
3010 	}
3011 
3012 	//needs to be called at last:
3013 	list.InitList("Add Geometric Element", "Select GeomElement:");
3014 
3015 	list.DoModal();
3016 
3017 	if (list.item_selected)
3018 	{
3019 		AutoSavembs();	//$ DR 2013-03-19
3020 		//int nelem = pWCDI->CallCompFunction(9,0,list.item_selected); //action=9: add geomelement 'list.item_selected'
3021 		int nelem = pWCDI->GetObjectFactory()->AddObject(OFCGeomElement, list.item_selected);
3022 
3023 		if (nelem>0)
3024 		{
3025 			if (EditElementProperties(nelem,16+2)) //16==Edit drawelement, 2==Add
3026 			{
3027 				//pWCDI->SetModelData_Initialized(0);						//$ DR 2013-02-04
3028 				pWCDI->CallCompFunction(3);										// Assemble				//$ DR 2013-10-11 not in ModelChanged anymore
3029 				pWCDI->CallCompFunction(1);										// SetInitialConditions //$ DR 2013-10-11 not in ModelChanged anymore
3030 				ModelChanged();																//$ DR 2013-02-04
3031 			}
3032 			else
3033 			{
3034 				//delete element:
3035 				pWCDI->CallCompFunction(10,0,nelem);
3036 			}
3037 		}
3038 	}
3039 }
3040 
3041 //$ DR 2012-12 button added
OnAddobjectAddmaterial()3042 void CWCDriver3DDlg::OnAddobjectAddmaterial()
3043 {
3044 	if(pWCDI->IsComputationInProgress()) {AfxMessageBox("Computation is running! Operation not possible."); return;}
3045 
3046 	CustomListDialog list;
3047 	int nMaterials = pWCDI->GetObjectFactory()->GetAvailableTypesCount(OFCMaterial);
3048 	for (int i=1; i <= nMaterials; i++)
3049 	{
3050 		CString name = pWCDI->GetObjectFactory()->GetTypeName(OFCMaterial,i);
3051 		int typeflags = pWCDI->GetObjectFactory()->GetTypeFlags(OFCMaterial,i);
3052 		if( !(pWCDI->GetObjectFactory()->ExcludeExperimentalObjects()) || !(typeflags & TAENotInRelease) )
3053 		{
3054 			list.AddString(name, i);
3055 		}
3056 	}
3057 
3058 	//needs to be called at last:
3059 	list.InitList("Add Material", "Select Material:");
3060 
3061 	list.DoModal();
3062 	if (list.item_selected)
3063 	{
3064 		AutoSavembs();	//$ DR 2013-03-19
3065 		int nmat = pWCDI->GetObjectFactory()->AddObject(OFCMaterial,list.item_selected);
3066 		if (nmat>0)
3067 		{
3068 			if (EditElementProperties(nmat,66))
3069 			{
3070 				//pWCDI->SetModelData_Initialized(0);						//$ DR 2013-02-04
3071 				pWCDI->CallCompFunction(3);										// Assemble				//$ DR 2013-10-11 not in ModelChanged anymore
3072 				pWCDI->CallCompFunction(1);										// SetInitialConditions //$ DR 2013-10-11 not in ModelChanged anymore
3073 				ModelChanged();																//$ DR 2013-02-04
3074 			}
3075 			else
3076 			{
3077 				//delete material:
3078 				pWCDI->CallCompFunction(15,0,nmat);
3079 			}
3080 		}
3081 		else
3082 		{
3083 			if (nmat == -1) AfxMessageBox("Error: Selected material type does not exist!!!\n");
3084 		}
3085 	}
3086 }
3087 
3088 //$ DR 2013-01 button added
OnAddbeam3dproperties()3089 void CWCDriver3DDlg::OnAddbeam3dproperties()
3090 {
3091 	if(pWCDI->IsComputationInProgress()) {AfxMessageBox("Computation is running! Operation not possible."); return;}
3092 
3093 	CustomListDialog list;
3094 	int nBeamProp = pWCDI->GetObjectFactory()->GetAvailableTypesCount(OFCBeamProperties);
3095 	//int nMaterials = pWCDI->GetObjectFactory()->GetAvailableTypesCount(OFCMaterial);
3096 	for (int i=1; i <= nBeamProp; i++)
3097 	{
3098 		CString name = pWCDI->GetObjectFactory()->GetTypeName(OFCBeamProperties,i);
3099 		int typeflags = pWCDI->GetObjectFactory()->GetTypeFlags(OFCBeamProperties,i);
3100 		if( !(pWCDI->GetObjectFactory()->ExcludeExperimentalObjects()) || !(typeflags & TAENotInRelease) )
3101 		{
3102 			list.AddString(name, i);
3103 		}
3104 	}
3105 
3106 	//needs to be called at last:
3107 	list.InitList("Add BeamProperties", "Select BeamProperties:");
3108 
3109 	list.DoModal();
3110 	if (list.item_selected)
3111 	{
3112 		AutoSavembs();	//$ DR 2013-03-19
3113 		int nmat = pWCDI->GetObjectFactory()->AddObject(OFCBeamProperties, list.item_selected);
3114 
3115 		if (nmat>0)
3116 		{
3117 			if (EditElementProperties(nmat,66))
3118 			{
3119 				//pWCDI->SetModelData_Initialized(0);						//$ DR 2013-02-04
3120 				pWCDI->CallCompFunction(3);										// Assemble				//$ DR 2013-10-11 not in ModelChanged anymore
3121 				pWCDI->CallCompFunction(1);										// SetInitialConditions //$ DR 2013-10-11 not in ModelChanged anymore
3122 				ModelChanged();																//$ DR 2013-02-04
3123 			}
3124 			else
3125 			{
3126 				//delete material:
3127 				pWCDI->CallCompFunction(15,0,nmat);
3128 			}
3129 		}
3130 		else
3131 		{
3132 			if (nmat == -1) AfxMessageBox("Error: Selected material type does not exist!!!\n");
3133 		}
3134 	}
3135 }
3136 
3137 //$ DR 2012-10 button added
OnAddload()3138 void CWCDriver3DDlg::OnAddload()
3139 {
3140 	if(pWCDI->IsComputationInProgress()) {AfxMessageBox("Computation is running! Operation not possible."); return;}
3141 
3142 	// create list for choosing the load-type
3143 	CustomListDialog list;
3144 	int nLoads = pWCDI->GetObjectFactory()->GetAvailableTypesCount(OFCLoad);
3145 	for (int i=1; i <= nLoads; i++)
3146 	{
3147 		CString name = pWCDI->GetObjectFactory()->GetTypeName(OFCLoad,i);
3148 		int typeflags = pWCDI->GetObjectFactory()->GetTypeFlags(OFCLoad,i);
3149 		if( !(pWCDI->GetObjectFactory()->ExcludeExperimentalObjects()) || !(typeflags & TAENotInRelease) )
3150 		{
3151 			list.AddString(name, i);
3152 		}
3153 	}
3154 
3155 	//needs to be called at last:
3156 	list.InitList("Add load", "Select load type to be added:");
3157 
3158 	//add items to list:
3159 	list.DoModal();
3160 
3161 	if (list.item_selected)
3162 	{
3163 		AutoSavembs();	//$ DR 2013-03-19
3164 		//int nload = pWCDI->CallCompFunction(6,0,list.item_selected);	// add load of specified type
3165 		int nload = pWCDI->GetObjectFactory()->AddObject(OFCLoad, list.item_selected);
3166 
3167 		if (nload>0)
3168 		{
3169 			if (EditElementProperties(nload,6))
3170 			{
3171 				//pWCDI->SetModelData_Initialized(0);						//$ DR 2013-02-04
3172 				pWCDI->CallCompFunction(3);										// Assemble				//$ DR 2013-10-11 not in ModelChanged anymore
3173 				pWCDI->CallCompFunction(1);										// SetInitialConditions //$ DR 2013-10-11 not in ModelChanged anymore
3174 				ModelChanged();																//$ DR 2013-02-04
3175 			}
3176 			else
3177 			{
3178 				//delete element:
3179 				pWCDI->CallCompFunction(5,0,nload);
3180 			}
3181 		}
3182 		else
3183 		{
3184 			if (nload == -1) AfxMessageBox("Error: Selected load type does not exist!!!\n");
3185 		}
3186 	}
3187 }
3188 
3189 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3190 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3191 // Edit existing objects
3192 
OnEditEditbody()3193 void CWCDriver3DDlg::OnEditEditbody()
3194 {
3195 	if(pWCDI->IsComputationInProgress())
3196 	{
3197 		AfxMessageBox("Computation is running! Edit not possible.");
3198 		return;
3199 	}
3200 
3201 	int nelem;
3202 
3203 	CustomListDialog list;
3204 	list.SetPixelSize(200,400);
3205 
3206 	ElementDataContainer edc;
3207 	pWCDI->CallCompFunction(202,0,0,&edc); //edc contains element names
3208 
3209 	for (int i=1; i <= edc.Length(); i++)
3210 	{
3211 		char str[16];
3212 		sprintf_s(str,"%d-", i);
3213 		list.AddString(CString(str)+CString(edc.Get(i).GetDataName()), i);
3214 	}
3215 
3216 	list.SetUseEditItem(1);
3217 	list.InitList("Edit Element Properties", "Select element to edit:");
3218 
3219 	list.DoModal();
3220 
3221 	nelem = list.item_selected;
3222 
3223 	if (nelem)
3224 	{
3225 		if (EditElementProperties(nelem,1))
3226 		{
3227 			pWCDI->CallCompFunction(3);										// Assemble				//$ DR 2013-10-11 not in ModelChanged anymore
3228 			pWCDI->CallCompFunction(1);										// SetInitialConditions //$ DR 2013-10-11 not in ModelChanged anymore
3229 			ModelChanged();
3230 		}
3231 	}
3232 
3233 }
3234 
OnEditEditnode()3235 void CWCDriver3DDlg::OnEditEditnode()
3236 {
3237 	if(pWCDI->IsComputationInProgress())
3238 	{
3239 		AfxMessageBox("Computation is running! Edit not possible.");
3240 		return;
3241 	}
3242 	int nelem;
3243 
3244 	CustomListDialog list;
3245 	list.SetPixelSize(200,400);
3246 
3247 	ElementDataContainer edc;
3248 	pWCDI->CallCompFunction(207,0,0,&edc); //edc contains node names
3249 
3250 	for (int i=1; i <= edc.Length(); i++)
3251 	{
3252 		char str[16];
3253 		sprintf_s(str,"%d-", i);
3254 		list.AddString(CString(str)+CString(edc.Get(i).GetDataName()), i);
3255 	}
3256 
3257 	list.SetUseEditItem(1);
3258 	list.InitList("Edit Node", "Select node to edit:");
3259 
3260 	list.DoModal();
3261 
3262 	nelem = list.item_selected;
3263 
3264 	if (nelem)
3265 	{
3266 		if (EditElementProperties(nelem,32)) //edit node
3267 		{
3268 			ModelChanged();
3269 		}
3270 	}
3271 	else
3272 	{
3273 		//AfxMessageBox("Invalid number selected!");
3274 	}
3275 }
3276 
OnEditEditsensor()3277 void CWCDriver3DDlg::OnEditEditsensor()
3278 {
3279 	if(pWCDI->IsComputationInProgress())
3280 	{
3281 		AfxMessageBox("Computation is running! Edit not possible.");
3282 		return;
3283 	}
3284 	int nelem;
3285 
3286 	CustomListDialog list;
3287 	list.SetPixelSize(200,400);
3288 
3289 	ElementDataContainer edc;
3290 	pWCDI->CallCompFunction(203,0,0,&edc); //edc contains sensor names
3291 
3292 	for (int i=1; i <= edc.Length(); i++)
3293 	{
3294 		char str[16];
3295 		sprintf_s(str,"%d-", i);
3296 		list.AddString(CString(str)+CString(edc.Get(i).GetDataName()), i);
3297 	}
3298 
3299 	list.SetUseEditItem(1);
3300 	list.InitList("Edit Sensor", "Select sensor to edit:");
3301 
3302 	list.DoModal();
3303 
3304 	nelem = list.item_selected;
3305 
3306 	if (nelem)
3307 	{
3308 		if (EditElementProperties(nelem,8)) //edit sensor
3309 		{
3310 			SetModelModified();
3311 			//only redraw to show new sensors, nothing else needs to be done
3312 			GLDrawWnd.Redraw();
3313 		}
3314 	}
3315 	else
3316 	{
3317 		//AfxMessageBox("Invalid number selected!");
3318 	}
3319 }
3320 
OnEditEditgeomelement()3321 void CWCDriver3DDlg::OnEditEditgeomelement()
3322 {
3323 	if(pWCDI->IsComputationInProgress())
3324 	{
3325 		AfxMessageBox("Computation is running! Edit not possible.");
3326 		return;
3327 	}
3328 	int nelem;
3329 
3330 	CustomListDialog list;
3331 	list.SetPixelSize(250,400);
3332 
3333 	ElementDataContainer edc;
3334 	pWCDI->CallCompFunction(205,0,0,&edc); //edc contains GeomElement names
3335 
3336 	for (int i=1; i <= edc.Length(); i++)
3337 	{
3338 		char str[16];
3339 		sprintf_s(str,"%d-", i);
3340 		list.AddString(CString(str)+CString(edc.Get(i).GetDataName()), i);
3341 	}
3342 
3343 	list.SetUseEditItem(1);
3344 	list.InitList("Edit Geometric Element", "Select GeomElement to edit:");
3345 
3346 	list.DoModal();
3347 
3348 	nelem = list.item_selected;
3349 
3350 	if (nelem)
3351 	{
3352 		if (EditElementProperties(nelem,16)) //edit sensor
3353 		{
3354 			SetModelModified();
3355 			GLDrawWnd.ContentsChanged(0); //fit on screen and redraw
3356 		}
3357 	}
3358 	else
3359 	{
3360 		//AfxMessageBox("Invalid number selected!");
3361 	}
3362 }
3363 
OnEditEditmaterial()3364 void CWCDriver3DDlg::OnEditEditmaterial()
3365 {
3366 	if(pWCDI->IsComputationInProgress())
3367 	{
3368 		AfxMessageBox("Computation is running! Edit not possible.");
3369 		return;
3370 	}
3371 	int nelem;
3372 
3373 	CustomListDialog list;
3374 	list.SetPixelSize(250,400);
3375 
3376 	ElementDataContainer edc;
3377 	pWCDI->CallCompFunction(209,0,0,&edc); //edc contains material names
3378 
3379 	for (int i=1; i <= edc.Length(); i++)
3380 	{
3381 		char str[16];
3382 		sprintf_s(str,"%d-", i);
3383 		list.AddString(CString(str)+CString(edc.Get(i).GetDataName()), i);
3384 	}
3385 
3386 	list.SetUseEditItem(1);
3387 	list.InitList("Edit Materials", "Select Material to edit:");
3388 
3389 	list.DoModal();
3390 
3391 	nelem = list.item_selected;
3392 
3393 	if (nelem)
3394 	{
3395 		if (EditElementProperties(nelem,64)) //edit material
3396 		{
3397 			SetModelModified();
3398 			GLDrawWnd.ContentsChanged(0); //fit on screen and redraw
3399 		}
3400 	}
3401 	else
3402 	{
3403 		//AfxMessageBox("Invalid number selected!");
3404 	}
3405 }
3406 
3407 
3408 //$ DR 2012-10: loads moved from element to edc
OnEditEditLoad()3409 void CWCDriver3DDlg::OnEditEditLoad()
3410 {
3411 	if(pWCDI->IsComputationInProgress())
3412 	{
3413 		AfxMessageBox("Computation is running! Edit not possible.");
3414 		return;
3415 	}
3416 
3417 	int nload;
3418 
3419 	CustomListDialog list;
3420 	list.SetPixelSize(200,400);
3421 
3422 	ElementDataContainer edc;
3423 	pWCDI->CallCompFunction(214,0,0,&edc); //edc contains load names
3424 
3425 	for (int i=1; i <= edc.Length(); i++)
3426 	{
3427 		char str[16];
3428 		sprintf_s(str,"%d-", i);
3429 		list.AddString(CString(str)+CString(edc.Get(i).GetDataName()), i);
3430 	}
3431 
3432 	list.SetUseEditItem(1);
3433 	list.InitList("Edit Load Properties", "Select load to edit:");
3434 
3435 	list.DoModal();
3436 
3437 	nload = list.item_selected;
3438 
3439 
3440 	if (nload)
3441 	{
3442 		if (EditElementProperties(nload,4))
3443 		{
3444 			ModelChanged();
3445 		}
3446 	}
3447 }
3448 
3449 
3450 
3451 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3452 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3453 // Delete existing objects
3454 
OnEditDeleteElement()3455 void CWCDriver3DDlg::OnEditDeleteElement()
3456 {
3457 	if(pWCDI->IsComputationInProgress())
3458 	{
3459 		AfxMessageBox("Computation is running! Edit not possible.");
3460 		return;
3461 	}
3462 
3463 	CustomListDialog list;
3464 	list.SetPixelSize(200,400);
3465 
3466 	ElementDataContainer edc;
3467 	pWCDI->CallCompFunction(202,0,0,&edc); //edc contains element names
3468 
3469 	for (int i=1; i <= edc.Length(); i++)
3470 	{
3471 		char str[16];
3472 		sprintf_s(str,"%d-", i);
3473 		list.AddString(CString(str)+CString(edc.Get(i).GetDataName()), i);
3474 	}
3475 
3476 	list.SetUseEditItem(1);
3477 	list.InitList("Delete Element", "DELETE element:");
3478 
3479 	list.DoModal();
3480 	int n = list.item_selected;
3481 	if (n != 0)
3482 	{
3483 		if(AfxMessageBox(CString("Are you sure to delete the element \nand reset the computation?"),MB_YESNO | MB_ICONQUESTION) == IDYES)
3484 		{
3485 			pWCDI->CallCompFunction(4,0,n);
3486 			pWCDI->CallCompFunction(3);										// Assemble				//$ DR 2013-10-11 not in ModelChanged anymore
3487 			pWCDI->CallCompFunction(1);										// SetInitialConditions //$ DR 2013-10-11 not in ModelChanged anymore
3488 			ModelChanged();
3489 		}
3490 	}
3491 }
3492 
3493 
OnEditDeleteNode()3494 void CWCDriver3DDlg::OnEditDeleteNode()
3495 {
3496 	if(pWCDI->IsComputationInProgress())
3497 	{
3498 		AfxMessageBox("Computation is running! Edit not possible.");
3499 		return;
3500 	}
3501 
3502 	CustomListDialog list;
3503 	list.SetPixelSize(220,400);
3504 
3505 	ElementDataContainer edc;
3506 	pWCDI->CallCompFunction(207,0,0,&edc); //edc contains node names
3507 
3508 	for (int i=1; i <= edc.Length(); i++)
3509 	{
3510 		char str[16];
3511 		sprintf_s(str,"%d-", i);
3512 		list.AddString(CString(str)+CString(edc.Get(i).GetDataName()), i);
3513 	}
3514 
3515 	list.SetUseEditItem(1);
3516 	list.InitList("Delete Node", "Select node to delete:");
3517 
3518 	list.DoModal();
3519 	int n = list.item_selected;
3520 	if (n != 0)
3521 	{
3522 		if(AfxMessageBox(CString("Are you sure to delete the node \nand reset the computation?"),MB_YESNO | MB_ICONQUESTION) == IDYES)
3523 		{
3524 			pWCDI->CallCompFunction(12,0,n);
3525 			pWCDI->CallCompFunction(3);										// Assemble				//$ DR 2013-10-11 not in ModelChanged anymore
3526 			pWCDI->CallCompFunction(1);										// SetInitialConditions //$ DR 2013-10-11 not in ModelChanged anymore
3527 			ModelChanged();
3528 		}
3529 	}
3530 }
3531 
3532 
3533 
3534 
OnEditDeleteSensor()3535 void CWCDriver3DDlg::OnEditDeleteSensor()
3536 {
3537 	if(pWCDI->IsComputationInProgress())
3538 	{
3539 		AfxMessageBox("Computation is running! Edit not possible.");
3540 		return;
3541 	}
3542 	CustomListDialog list;
3543 	list.SetPixelSize(220,400);
3544 
3545 	ElementDataContainer edc;
3546 	pWCDI->CallCompFunction(203,0,0,&edc); //edc contains sensor names
3547 
3548 	for (int i=1; i <= edc.Length(); i++)
3549 	{
3550 		char str[16];
3551 		sprintf_s(str,"%d-", i);
3552 		list.AddString(CString(str)+CString(edc.Get(i).GetDataName()), i);
3553 	}
3554 
3555 	list.SetUseEditItem(1);
3556 	list.InitList("Delete Sensor", "Select sensor to delete:");
3557 
3558 	list.DoModal();
3559 	int n = list.item_selected;
3560 	if (n != 0)
3561 	{
3562 		if(AfxMessageBox(CString("Are you sure to delete the sensor \nand reset the computation?"),MB_YESNO | MB_ICONQUESTION) == IDYES)
3563 		{
3564 			pWCDI->CallCompFunction(8,0,n);
3565 			pWCDI->CallCompFunction(3);										// Assemble				//$ DR 2013-10-11 not in ModelChanged anymore
3566 			pWCDI->CallCompFunction(1);										// SetInitialConditions //$ DR 2013-10-11 not in ModelChanged anymore
3567 			ModelChanged();
3568 		}
3569 	}
3570 }
3571 
3572 
OnEditDeleteGeomelement()3573 void CWCDriver3DDlg::OnEditDeleteGeomelement()
3574 {
3575 	if(pWCDI->IsComputationInProgress())
3576 	{
3577 		AfxMessageBox("Computation is running! Edit not possible.");
3578 		return;
3579 	}
3580 	CustomListDialog list;
3581 	list.SetPixelSize(250,400);
3582 
3583 	ElementDataContainer edc;
3584 	pWCDI->CallCompFunction(205,0,0,&edc); //edc contains GeomElement names
3585 
3586 	for (int i=1; i <= edc.Length(); i++)
3587 	{
3588 		char str[16];
3589 		sprintf_s(str,"%d-", i);
3590 		list.AddString(CString(str)+CString(edc.Get(i).GetDataName()), i);
3591 	}
3592 
3593 	list.SetUseEditItem(1);
3594 	list.InitList("Delete Geometric Element", "Select GeomElement to delete:");
3595 
3596 	list.DoModal();
3597 	int n = list.item_selected;
3598 	if (n != 0)
3599 	{
3600 		if(AfxMessageBox(CString("Are you sure to delete the GeomElement \nand reset the computation?"),MB_YESNO | MB_ICONQUESTION) == IDYES)
3601 		{
3602 			pWCDI->CallCompFunction(10,0,n);
3603 			pWCDI->CallCompFunction(3);										// Assemble				//$ DR 2013-10-11 not in ModelChanged anymore
3604 			pWCDI->CallCompFunction(1);										// SetInitialConditions //$ DR 2013-10-11 not in ModelChanged anymore
3605 			ModelChanged();
3606 		}
3607 	}
3608 }
3609 
3610 
OnEditDeleteMaterial()3611 void CWCDriver3DDlg::OnEditDeleteMaterial()
3612 {
3613 	if(pWCDI->IsComputationInProgress())
3614 	{
3615 		AfxMessageBox("Computation is running! Edit not possible.");
3616 		return;
3617 	}
3618 	CustomListDialog list;
3619 	list.SetPixelSize(250,400);
3620 
3621 	ElementDataContainer edc;
3622 	pWCDI->CallCompFunction(209,0,0,&edc); //edc contains material names
3623 
3624 	for (int i=1; i <= edc.Length(); i++)
3625 	{
3626 		char str[16];
3627 		sprintf_s(str,"%d-", i);
3628 		list.AddString(CString(str)+CString(edc.Get(i).GetDataName()), i);
3629 	}
3630 
3631 	list.SetUseEditItem(1);
3632 	list.InitList("Delete Material", "Select Material to delete:");
3633 
3634 	list.DoModal();
3635 	int n = list.item_selected;
3636 	if (n != 0)
3637 	{
3638 		if(AfxMessageBox(CString("Are you sure to delete the material \nand reset the computation?"),MB_YESNO | MB_ICONQUESTION) == IDYES)
3639 		{
3640 			pWCDI->CallCompFunction(15,0,n);
3641 			pWCDI->CallCompFunction(3);										// Assemble				//$ DR 2013-10-11 not in ModelChanged anymore
3642 			pWCDI->CallCompFunction(1);										// SetInitialConditions //$ DR 2013-10-11 not in ModelChanged anymore
3643 			ModelChanged();
3644 		}
3645 	}
3646 }
3647 
OnEditDeleteLoad()3648 void CWCDriver3DDlg::OnEditDeleteLoad()
3649 {
3650 	if(pWCDI->IsComputationInProgress())
3651 	{
3652 		AfxMessageBox("Computation is running! Edit not possible.");
3653 		return;
3654 	}
3655 
3656 	CustomListDialog list;
3657 	list.SetPixelSize(200,400);
3658 
3659 	ElementDataContainer edc;
3660 	pWCDI->CallCompFunction(214,0,0,&edc); //edc contains load names
3661 
3662 	for (int i=1; i <= edc.Length(); i++)
3663 	{
3664 		char str[16];
3665 		sprintf_s(str,"%d-", i);
3666 		list.AddString(CString(str)+CString(edc.Get(i).GetDataName()), i);
3667 	}
3668 
3669 	list.SetUseEditItem(1);
3670 	list.InitList("Delete Load", "Select load to delete:");
3671 
3672 	list.DoModal();
3673 	int n = list.item_selected;
3674 	if (n != 0)
3675 	{
3676 		if(AfxMessageBox(CString("Are you sure to delete the load \nand reset the computation?"),MB_YESNO | MB_ICONQUESTION) == IDYES)
3677 		{
3678 			pWCDI->CallCompFunction(5,0,n);
3679 			pWCDI->CallCompFunction(3);										// Assemble				//$ DR 2013-10-11 not in ModelChanged anymore
3680 			pWCDI->CallCompFunction(1);										// SetInitialConditions //$ DR 2013-10-11 not in ModelChanged anymore
3681 			ModelChanged();
3682 		}
3683 	}
3684 }
3685 
3686 
3687 
3688 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3689 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3690 //other menu calls:
3691 
OnViewDefaultview1()3692 void CWCDriver3DDlg::OnViewDefaultview1()
3693 {
3694 	GLDrawWnd.OnButtonStandardViewXyz();
3695 }
3696 
OnViewXY()3697 void CWCDriver3DDlg::OnViewXY()
3698 {
3699 	GLDrawWnd.OnButtonStandardViewXy();
3700 }
3701 
OnViewXZ()3702 void CWCDriver3DDlg::OnViewXZ()
3703 {
3704 	GLDrawWnd.OnButtonStandardViewXz();
3705 }
3706 
OnViewYZ()3707 void CWCDriver3DDlg::OnViewYZ()
3708 {
3709 	GLDrawWnd.OnButtonStandardViewYz();
3710 }
3711 
3712 
3713 
OnMenuHelp()3714 void CWCDriver3DDlg::OnMenuHelp()
3715 {
3716 	//GLDrawWnd.SetProgramDirectoryAsCurrent();
3717 	CString dir = GLDrawWnd.GetProgramDirectory();
3718 
3719 	dir.Replace('\\','/');
3720 	dir.Replace(" ","%20");
3721 
3722 	//CString goal = CString("file:///") + dir + CString("/../documentation/hotint_docu_online.html");
3723 	//AddText(goal);
3724 	//ShellExecute(NULL, "open", "IEXPLORE.EXE", goal, NULL, SW_SHOW);
3725 
3726 	//$ DR 2013-01-23 new docu:
3727 	int l = dir.GetLength();
3728 	//AddText(dir);
3729 	dir.MakeReverse();
3730 	//AddText(dir);
3731 	int pos = dir.Find("/");	// position of last /
3732 	dir.MakeReverse();
3733 	CString goal = dir.Left(l-pos) + CString("documentation/");
3734 	AddText(goal);
3735 	//ShellExecute(NULL, "open", "D:/cpp/HotInt_V1/documentation/", NULL, NULL, SW_SHOWNORMAL);
3736 	ShellExecute(NULL, "open", goal, NULL, NULL, SW_SHOWNORMAL);
3737 
3738 }
3739 
3740 
3741 
3742 
OnViewRobotoptions()3743 void CWCDriver3DDlg::OnViewRobotoptions()
3744 {
3745 	//AfxMessageBox("robot options");
3746 
3747 	// TODO: F�gen Sie hier Ihren Befehlsbehandlungscode ein.
3748 	EditElementProperties(0, 256); //edit robot options
3749 
3750 	GLDrawWnd.Redraw();
3751 }
3752 
3753 
OnSystemEditmodelparameters()3754 void CWCDriver3DDlg::OnSystemEditmodelparameters()
3755 {
3756 
3757 	CTreeViewCustomEditDialog ced; ced.SetWCDI(pWCDI); ced.SetGLDrawWnd(&GLDrawWnd);
3758 	ElementDataContainer edc;
3759 	pWCDI->CallCompFunction(211, 0, 0, &edc); //get model data
3760 
3761 	const char* options_text = "SolverOptions";
3762 	//look for SolverOptions:
3763 	int findso = edc.Find(options_text);
3764 	ElementDataContainer* save_so = 0;
3765 	if (findso)
3766 	{
3767 		save_so = edc.Get(findso).GetEDC()->GetCopy();
3768 		edc.Delete(findso);
3769 	}
3770 
3771 	ElementDataContainer edc_root; //in order to show root entries
3772 	ElementData root;
3773 	const char* rt = "root";
3774 	root.SetEDC(&edc, rt);
3775 	edc_root.Add(root);
3776 
3777 	//ced.SetDialogName("Edit Model Parameters");
3778 	ced.SetDialogName("Show Global Variables");	//$ DR 2013-06-05
3779 
3780 	ced.SetElementDataContainer(&edc_root);
3781 
3782 	ElementData* edr = edc_root.TreeFind(rt);
3783 	ElementDataContainer* edcnew = edr->GetEDC();
3784 
3785 	if (ced.DoModal() != IDCANCEL)
3786 	{
3787 		if (save_so)
3788 		{
3789 			ElementData ed;
3790 			ed.SetEDC(save_so, options_text);
3791 			edcnew->Add(ed);
3792 		}
3793 
3794 		pWCDI->CallCompFunction(211, 1, 0, edcnew); //set model data
3795 		//if SolverOptions have been there, replace them:
3796 
3797 		pWCDI->GetUserInterface()->CallWCDriverFunction(6); //call CWCDriver3DDlg::ModelChanged()
3798 		pWCDI->CallCompFunction(20,3); //Initialize()
3799 		GLDrawWnd.SendMessage(WM_REDRAW);
3800 
3801 	}
3802 }
3803 
OnSystemLoadmodelparameter()3804 void CWCDriver3DDlg::OnSystemLoadmodelparameter()
3805 {
3806 	if(pWCDI->IsComputationInProgress())
3807 	{
3808 		AfxMessageBox("Computation is running, file can not be loaded!");
3809 		return;
3810 	}
3811 
3812 	if(pWCDI->GetNElements() != 0 && !(AfxMessageBox("Discard all body information?",MB_YESNO | MB_ICONQUESTION) == IDYES))
3813 	{
3814 		return;
3815 	}
3816 
3817 	static char BASED_CODE szFilter[] = "ModelDataFile (*.txt)|*.txt|All Files (*.*)|*.*||";
3818 
3819 	CFileDialog fd(TRUE,"mbs",0,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ENABLESIZING|OFN_FILEMUSTEXIST ,szFilter); //true=load, false=save
3820 	//fd.m_pOFN->lpstrTitle = "Open MBS file";
3821 
3822 	if(fd.DoModal() == IDCANCEL) {return;}
3823 
3824 	if (fd.GetPathName().GetLength() != 0) //user did select file?
3825 	{
3826 		pWCDI->SetTOption(88, fd.GetPathName()); //store actual whole dirname + filename (=pathname)
3827 
3828 		pWCDI->CallCompFunction(211, 2); //load model data
3829 
3830 		pWCDI->GetUserInterface()->CallWCDriverFunction(6); //call CWCDriver3DDlg::ModelChanged()
3831 		pWCDI->CallCompFunction(20,3); //Initialize()
3832 		GLDrawWnd.SendMessage(WM_REDRAW);
3833 
3834 
3835 	}
3836 
3837 
3838 }
3839 
OnSystemSavemodeldata()3840 void CWCDriver3DDlg::OnSystemSavemodeldata()
3841 {
3842 	static char BASED_CODE szFilter[] = "ModelDataFile (*.txt)|*.txt|All Files (*.*)|*.*||";
3843 
3844 	CFileDialog fd(FALSE,"mbs",0,OFN_HIDEREADONLY|OFN_ENABLESIZING|OFN_OVERWRITEPROMPT,szFilter); //true=load, false=save
3845 	if(fd.DoModal() == IDCANCEL) {return;}
3846 
3847 
3848 	if (fd.GetPathName().GetLength() != 0) //user did select file?
3849 	{
3850 		pWCDI->SetTOption(88, fd.GetPathName()); //store actual dirname + filename (=pathname)
3851 
3852 		pWCDI->CallCompFunction(211, 3); //save model data
3853 	}
3854 
3855 }
3856 
3857 
3858 
3859 //edit all model parameters within an EDC
OnViewEditalloptions()3860 void CWCDriver3DDlg::OnViewEditalloptions()
3861 {
3862 	CTreeViewCustomEditDialog ced; ced.SetWCDI(pWCDI); ced.SetGLDrawWnd(&GLDrawWnd);
3863 	ElementDataContainer edc;
3864 	pWCDI->CallCompFunction(210, 0, 0, &edc); //get model data
3865 
3866 	ced.SetDialogName("Edit All Options");
3867 	ced.SetElementDataContainer(&edc);
3868 	ced.SetUseApply(1, 210, 1, 0);		// these are the codes of the functions for various actions available in the dialog
3869 	ced.DoModal();
3870 }
3871 
OnViewShowprogressbar()3872 void CWCDriver3DDlg::OnViewShowprogressbar()
3873 {
3874 	CallWCDriverFunction(10,1);
3875 }
3876 
OnResultsPlottooldialog()3877 void CWCDriver3DDlg::OnResultsPlottooldialog()
3878 {
3879 	CPlotToolDlg* activeplottool;
3880 	GetPlotToolDlg(activeplottool);
3881 }
3882 
3883 // select (autocreate) a PlotToolDialog
3884 // chose number = -1 to force creation of a new dialog
3885 // chose number = 0 to pick first visible
3886 // chose number > 0 to pick a certain plottool dialog ( create a new one if it does not exist
GetPlotToolDlg(CPlotToolDlg * & dialogPlotTool,int number)3887 int CWCDriver3DDlg::GetPlotToolDlg(CPlotToolDlg*& dialogPlotTool, int number)
3888 {
3889 	if( number <= PlotToolArray.Length() && number > 0) // pick existing
3890 	{
3891 		dialogPlotTool = PlotToolArray(number);
3892 		dialogPlotTool->ShowWindow(SW_SHOW);
3893 		return number;
3894 	}
3895 
3896 	if( number == 0 )
3897 	{
3898 		for (int i=1; i<= PlotToolArray.Length(); i++) // search for first visible
3899 		{
3900 			if(::IsWindowVisible(PlotToolArray(i)->m_hWnd))
3901 			{
3902 				dialogPlotTool = PlotToolArray(i);
3903 				dialogPlotTool->ShowWindow(SW_SHOW);
3904 				return i;
3905 			}
3906 		}
3907 	}
3908 
3909 	// create new dialog
3910 	return CreatePlotToolDlg(dialogPlotTool);
3911 }
3912 
3913 // create a new PlotToolDialog
CreatePlotToolDlg(CPlotToolDlg * & dialogPlotTool)3914 int CWCDriver3DDlg::CreatePlotToolDlg(CPlotToolDlg*& dialogPlotTool)
3915 {
3916 	dialogPlotTool = new CPlotToolDlg(this);
3917 
3918 	dialogPlotTool->SetWCDI(pWCDI);
3919 	dialogPlotTool->Create(IDD_DIALOG_PLOTTOOL,this);
3920 	dialogPlotTool->SetWindowTextA(mystr("PlotTool - Window #") + mystr(PlotToolArray.Length()+1));
3921 	dialogPlotTool->ShowWindow(SW_SHOW);
3922 
3923 // menu entry ?
3924 
3925 	return PlotToolArray.Add(dialogPlotTool);
3926 }
3927 
3928 // remove the PlotToolDlg from the list
DeletePlotToolDlg(CPlotToolDlg * dialogPlotTool)3929 int CWCDriver3DDlg::DeletePlotToolDlg(CPlotToolDlg* dialogPlotTool)
3930 {
3931 	int nr = PlotToolArray.Find(dialogPlotTool);
3932 	PlotToolArray.Erase(nr);
3933 
3934 	for(int i=nr; i<=PlotToolArray.Length(); i++)
3935 	{
3936 		PlotToolArray(i)->SetWindowTextA(mystr("PlotTool - Window #") + mystr(PlotToolArray.Length()+1));
3937 	}
3938 // menu entry ?
3939 
3940 	return PlotToolArray.Length();
3941 }
3942 
3943 
OnFileSelectmodel()3944 void CWCDriver3DDlg::OnFileSelectmodel()
3945 {
3946 
3947 	if(pWCDI->IsComputationInProgress())
3948 	{
3949 		AfxMessageBox("Computation is running, model can not be changed!");
3950 		return;
3951 	}
3952 
3953 	CustomListDialog list;
3954 	list.SetPixelSize(400,300);
3955 	list.dialogname = "Select Model File";
3956 	list.use_custom_check1=0;
3957 
3958 	ElementDataContainer edc;
3959 	pWCDI->CallCompFunction(20,1,0,&edc); //edc contains model function names
3960 
3961 	for (int i=1; i <= edc.Length(); i++)
3962 	{
3963 		list.AddString(CString(edc.Get(i).GetText()), i);
3964 	}
3965 	if (list.DoModal() == IDOK)
3966 	{
3967 		int nelem = list.item_selected;
3968 		if (CString(pWCDI->MBS_EDC_TreeGetString("GeneralOptions.ModelFile.internal_model_function_name")) != CString( edc.Get(nelem).GetText()))
3969 		{
3970 			pWCDI->MBS_EDC_TreeSetString(edc.Get(nelem).GetText(), "GeneralOptions.ModelFile.internal_model_function_name");
3971 			pWCDI->MBS_EDC_TreeSetString("","GeneralOptions.ModelFile.hotint_input_data_filename");
3972 
3973 			pWCDI->CallCompFunction(20,2); //tell MBS that model function has been changed!
3974 
3975 			AddRecentFile(edc.Get(nelem).GetText());
3976 
3977 			ModelChanged();
3978 
3979 			//$ DR old code:
3980 			//pWCDI->GetUserInterface()->CallWCDriverFunction(6); //call CWCDriver3DDlg::ModelChanged()
3981 			//pWCDI->CallCompFunction(20,2); //tell MBS that model function has been changed!
3982 			////pWCDI->CallCompFunction(1,1); //Initialize()
3983 			//GLDrawWnd.ContentsChanged();
3984 			////pGLDrawWnd->SendMessage(WM_REDRAW); // does not calculate a new value for Max
3985 
3986 			//DisplaySelectedModelName();
3987 		}
3988 	}
3989 }
3990 
OnEditComputationSteps()3991 void CWCDriver3DDlg::OnEditComputationSteps()
3992 {
3993 	CTreeViewCustomEditDialog ced; ced.SetWCDI(pWCDI); ced.SetGLDrawWnd(&GLDrawWnd);
3994 	ElementDataContainer edc_computationsteps;
3995 
3996 	ced.SetDialogName("NOT IMPLEMENTED YET - Edit Computation Steps - NOT IMPLEMENTED YET");
3997 	ced.SetElementDataContainer(&edc_computationsteps);
3998 	//ced.SetUseApply(1, 210, 1, 2);		// these are the codes of the functions for various actions available in the dialog
3999 	ced.DoModal();
4000 
4001 
4002 	// TODO: F�gen Sie hier Ihren Befehlsbehandlungscode ein.
4003 }
4004 
OnKeyDown(UINT nChar,UINT nRepCnt,UINT nFlags)4005 void CWCDriver3DDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
4006 {
4007 	CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
4008 }
4009 
4010 // DR 2013-06-12
OnSystemRunmacro()4011 void CWCDriver3DDlg::OnSystemRunmacro()
4012 {
4013 	if(pWCDI->IsComputationInProgress())
4014 	{
4015 		AfxMessageBox("Computation is running, macro can not be executed!");
4016 		return;
4017 	}
4018 
4019 	mystr path = pWCDI->MBS_EDC_TreeGetString("GeneralOptions.Paths.application_path");
4020 	//static char BASED_CODE szFilter[] = "HMC and HID files (*.hmc)|*.hmc|HID file (*.hid)|*.hid|All Files (*.*)|*.*||";
4021 	static char BASED_CODE szFilter[] = "HMC and HID files (*.hmc;*.hid)|*.hmc; *.hid|All Files (*.*)|*.*||";
4022 	CFileDialog fd(TRUE,"mbs",0,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_ENABLESIZING|OFN_FILEMUSTEXIST ,szFilter); //true=load, false=save
4023 	if(fd.DoModal() == IDCANCEL)
4024 	{
4025 		SetCurrentDirectory(path);	// reset path to old path
4026 		return;
4027 	}
4028 	SetCurrentDirectory(path);	// reset path to old path
4029 
4030 	GLDrawWnd.prohibit_redraw = 1;
4031 
4032 	CString pathname = fd.GetPathName();
4033 	CString filename = fd.GetFileName();
4034 
4035 	ElementDataContainer edc; ElementData ed;
4036 	ed.SetText(pathname, "File_name"); edc.Add(ed);
4037 	//ed.SetText("", "Directory_name"); edc.Add(ed);
4038 	ed.SetInt(1,"is_file"); edc.Add(ed);
4039 
4040 	AutoSavembs();
4041 	pWCDI->CallCompFunction(113,0,0,&edc);	// Add Model Data
4042 	pWCDI->CallCompFunction(210, 0, 0, &edc);		//$ DR 2012-12-06 update EDC of MBS
4043 
4044 	pWCDI->CallCompFunction(3);										// Assemble				//$ DR 2013-10-11 not in ModelChanged anymore
4045 	pWCDI->CallCompFunction(1);										// SetInitialConditions //$ DR 2013-10-11 not in ModelChanged anymore
4046 	ModelChanged();
4047 }
4048