//---------------------------------------------------------------------------- void medLogicWithManagers::OnFileSaveAs() //---------------------------------------------------------------------------- { if(m_VMEManager) { mafString save_default_folder = m_StorageSettings->GetDefaultSaveFolder(); save_default_folder.ParsePathName(); m_VMEManager->SetDirName(save_default_folder); int saved=m_VMEManager->MSFSaveAs(); //If there is a wizard running we need to continue it after save operation if (m_WizardManager && m_WizardRunning) m_WizardManager->WizardContinue(saved!=MAF_ERROR); UpdateFrameTitle(); } }
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; SetIcon(LoadIcon(theApp.m_hInstance,MAKEINTRESOURCEW(IDR_MAINFRAME)),TRUE); SetIcon(LoadIcon(theApp.m_hInstance,MAKEINTRESOURCEW(IDR_MAINFRAME)),FALSE); // CMenu *pMainmenu = new CMenu; // pMainmenu->LoadMenu(IDR_MAINFRAME); // SetMenu(pMainmenu); UpdateFrameTitle(theApp.m_strUserName); m_pView = new CSXSView; CRect rcClient; GetClientRect(&rcClient); m_pView->Create(NULL,NULL,WS_VISIBLE|WS_CHILD,rcClient,this,0); return 0; }
//---------------------------------------------------------------------------- void medLogicWithManagers::OnEvent(mafEventBase *maf_event) //---------------------------------------------------------------------------- { if (mafEvent *e = mafEvent::SafeDownCast(maf_event)) { switch(e->GetId()) { case ABOUT_APPLICATION: { // trap the ABOUT_APPLICATION event and shows the about window with the application infos wxString message = m_AppTitle.GetCStr(); message += _(" Application "); message += m_Revision; wxMessageBox(message, "About Application"); mafLogMessage(wxString::Format("%s",m_Revision.GetCStr())); } break; case ID_GET_FILENAME: { e->SetString(&(m_VMEManager->GetFileName())); } break; case MENU_FILE_SNAPSHOT: { mafString msfFilename = m_VMEManager->GetFileName(); if (msfFilename.IsEmpty()) { mafString dirName = mafGetApplicationDirectory().c_str(); dirName << "\\data\\msf\\"; m_VMEManager->SetDirName(dirName); this->OnFileSaveAs(); this->OnEvent((mafEventBase*)&mafEvent(this,CAMERA_UPDATE)); msfFilename = m_VMEManager->GetFileName(); } wxString path, name, ext; wxSplitPath(msfFilename.GetCStr(),&path,&name,&ext); wxString imagesDirectoryName = path; imagesDirectoryName += "/images"; if (!::wxDirExists(imagesDirectoryName)) { ::wxMkdir(imagesDirectoryName); } wxDir imagesDirectory(imagesDirectoryName); wxString filename; int i = 0; bool cont = imagesDirectory.GetFirst(&filename); while ( cont ) { i++; cont = imagesDirectory.GetNext(&filename); } if (e->GetString() && !(e->GetString()->IsEmpty())) { mafString *imageFileName = new mafString(); imageFileName->Append(imagesDirectoryName.c_str()); imageFileName->Append("/"); imageFileName->Append(e->GetString()->GetCStr()); imageFileName->Append(wxString::Format("_%d",i)); imageFileName->Append(".png"); /*mafRWIBase::SafeDownCast(e->GetVtkObj())->SaveImage(imageFileName);*/ e->SetString(imageFileName); wxString path,name,ext; wxSplitPath(imageFileName->GetCStr(),&path,&name,&ext); wxString oldWD = wxGetWorkingDirectory(); wxSetWorkingDirectory(path); wxString command = "START "; command = command + name+"."+ext; wxExecute( command ); wxSetWorkingDirectory(oldWD); } else { wxString imageFileName = ""; mafViewCompound *v = mafViewCompound::SafeDownCast(m_ViewManager->GetSelectedView()); if (v) { imageFileName = imagesDirectoryName; imageFileName << "/"; wxString tmpImageFile; tmpImageFile << v->GetLabel(); tmpImageFile << i; tmpImageFile << ".png"; tmpImageFile.Replace(" ","_"); imageFileName << tmpImageFile; v->GetRWI()->SaveAllImages(imageFileName,v, m_ApplicationSettings->GetImageTypeId()); wxMessageBox(_("Snapshot saved!")); } else { mafView *v = m_ViewManager->GetSelectedView(); imageFileName = imagesDirectoryName; imageFileName << "/"; wxString tmpImageFile; tmpImageFile << v->GetLabel(); tmpImageFile << i; tmpImageFile << ".png"; tmpImageFile.Replace(" ","_"); imageFileName << tmpImageFile; if (v) { v->GetRWI()->SaveImage(imageFileName); wxMessageBox(_("Snapshot saved!")); } } wxString path,name,ext; wxSplitPath(imageFileName,&path,&name,&ext); wxString oldWD = wxGetWorkingDirectory(); wxSetWorkingDirectory(path); wxString command = "START "; command = command + name+"."+ext; wxShell( command ); wxSetWorkingDirectory(oldWD); } OnEvent(&mafEvent(this,WIZARD_RUN_CONTINUE,true)); } break; case MENU_WIZARD: //The event from the application menu if(m_WizardManager) m_WizardManager->WizardRun(e->GetArg()); break; case WIZARD_RUN_STARTING: { //Manage start event from the wizard lock window close button //and disabling toolbar mafGUIMDIChild *c = (mafGUIMDIChild *)m_Win->GetActiveChild(); if (c != NULL) c->SetAllowCloseWindow(false); WizardRunStarting(); } break; case WIZARD_RUN_TERMINATED: { //Manage end event from the wizard unlock window close button //and enabling toolbar mafGUIMDIChild *c = (mafGUIMDIChild *)m_Win->GetActiveChild(); if (c != NULL) c->SetAllowCloseWindow(true); WizardRunTerminated(); UpdateFrameTitle(); } break; case WIZARD_RUN_CONTINUE: { if (m_WizardManager && m_WizardRunning) m_WizardManager->WizardContinue(e->GetBool()); } break; case WIZARD_UPDATE_WINDOW_TITLE: { UpdateFrameTitle(); } break; case WIZARD_REQUIRED_VIEW: { //The wizard requires a specific view //searching on open views or open a new one mafView *view; const char *viewStr=e->GetString()->GetCStr(); view=m_ViewManager->GetFromList(viewStr); if (view) m_ViewManager->Activate(view); else m_ViewManager->ViewCreate(viewStr); } break; case WIZARD_DELETE_VIEW: { mafView *view; const char *viewStr=e->GetString()->GetCStr(); view=m_ViewManager->GetFromList(viewStr); if (view) { mafGUIMDIChild *c = (mafGUIMDIChild *)view->GetFrame(); m_ViewManager->ViewDelete(view); if (c != NULL) c->Destroy(); } } break; case WIZARD_RUN_OP: { //Running an op required from the wizard mafString *tmp=e->GetString(); mafLogMessage("wiz starting :%s",tmp->GetCStr()); m_CancelledBeforeOpStarting=true; UpdateFrameTitle(); m_OpManager->OpRun(*(e->GetString())); //If the op is started the value of m_CancelledBeforeOpStarting //is changed by OP_RUN_STARTING event if (m_CancelledBeforeOpStarting) { m_CancelledBeforeOpStarting=false; m_WizardManager->WizardContinue(false); } } break; case WIZARD_OP_DELETE: { //Running an op required from the wizard m_CancelledBeforeOpStarting=true; UpdateFrameTitle(); m_OpManager->OpRun(OP_DELETE); m_WizardManager->WizardContinue(true); } break; case WIZARD_OP_NEW: { //Running an op required from the wizard if(m_VMEManager) m_VMEManager->MSFNew(); m_WizardManager->WizardContinue(true); } break; case WIZARD_PAUSE: { UpdateFrameTitle(); m_OpManager->OpRun(e->GetOp()); } break; case WIZARD_RELOAD_MSF: { UpdateFrameTitle(); wxString file; file=m_VMEManager->GetFileName().GetCStr(); if(file.IsEmpty()) { mafLogMessage ("Reload requested whitout opened MSF"); //continue wizard with error m_WizardManager->WizardContinue(false); } else { int opened=m_VMEManager->MSFOpen(file); //continue wizard after open operation m_WizardManager->WizardContinue(opened!=MAF_ERROR); } } break; case OP_RUN_STARTING: { mafLogMessage("run starting"); m_CancelledBeforeOpStarting=false; mafLogicWithManagers::OnEvent(maf_event); } break; case OP_RUN_TERMINATED: { //if the operation was started from the wizard we continue the wizard execution if (m_WizardManager && m_WizardRunning) { m_WizardManager->WizardContinue(e->GetArg()); } //else we manage the operation end by unlock the close button and so on else { mafGUIMDIChild *c = (mafGUIMDIChild *)m_Win->GetActiveChild(); if (c != NULL) c->SetAllowCloseWindow(true); OpRunTerminated(); } } break; case MENU_VIEW_TOOLBAR: m_Win->ShowDockPane("wizardgauge",!m_Win->DockPaneIsShown("wizardgauge") ); m_Win->ShowDockPane("tmpwithtest",!m_Win->DockPaneIsShown("tmpwithtest") ); m_Win->ShowDockPane("separator",!m_Win->DockPaneIsShown("separator") ); mafLogicWithManagers::OnEvent(maf_event); break; case PROGRESSBAR_SHOW: { if (e->GetSender()==m_WizardManager) { m_WizardLabel->Enable(); m_WizardGauge->Enable(); } else mafLogicWithManagers::OnEvent(maf_event); } break; case PROGRESSBAR_HIDE: { if (e->GetSender()==m_WizardManager) { m_WizardGauge->SetValue(0); m_WizardGauge->Enable(false); m_WizardLabel->Enable(false); } else mafLogicWithManagers::OnEvent(maf_event); } break; case PROGRESSBAR_SET_VALUE: { if (e->GetSender()==m_WizardManager) m_WizardGauge->SetValue(e->GetArg()); else mafLogicWithManagers::OnEvent(maf_event); } break; default: //Call parent event manager mafLogicWithManagers::OnEvent(maf_event); break; } // end switch case } // end if SafeDowncast }