public Execute ( string command ) : bool | ||
command | string | El nombre del comando a ejecutar |
return | bool |
public bool Execute(string command)
{
// Clean command
command = command.Trim().ToLowerInvariant();
// Check cancel first
if (command.Equals("cancel"))
{
// Cancel View Command, Model Command and Selection if applicable
// (in that order, only one action per cancel)
if ((viewCmd != SelectionCommand || Canguro.View.GraphicViewManager.Instance.ActiveView.ModelRenderer.RenderOptions.ShowAnimated) && EndViewCommand != null)
EndViewCommand(this, new EndViewCommandArgs(viewCmd));
else
{
if (modelCmd != null)
{
if (!modelCmd.AllowCancel())
return false;
endModelCommand();
}
else
{
// If there was no ModelCommand, clear and reset selection
Canguro.Model.Model.Instance.UnSelectAll();
SelectionCommand.Reset();
}
}
IdleReset();
viewCmd = SelectionCommand;
if (StartViewCommand != null)
StartViewCommand(this, EventArgs.Empty);
mainFrm.ScenePanel.Cursor = SelectionCommand.DefaultCursor;
return true;
}
// Check if command exists
if (!commands.ContainsKey(command))
{
System.Windows.Forms.MessageBox.Show(Culture.Get("CommandNotFound") + ": '" + command + "'", Culture.Get("ActionNotPossibleTitle"), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
return false;
}
// Execute Command
// Prioritize View Commands
Command cmd = commands[command];
if (cmd is ViewCommand)
{
// If a series of viewCommands has ended (entered SelectionCommand)
// then send the EndViewCommand signal
// If Selection was doing anything and the viewCmd changes to zoom, pan, rotate, etc.
// (exits selection mode), reset SelectionCommand
if ((cmd == SelectionCommand) && (viewCmd != SelectionCommand) && (EndViewCommand != null))
EndViewCommand(this, new EndViewCommandArgs(viewCmd));
else if ((cmd != SelectionCommand) && (viewCmd == SelectionCommand))
// Tal vez en lugar de un Reset sea mejor un Cancel, para no perder el tracking
SelectionCommand.Reset();
// Instantiate and run new ViewCommand
ViewCommand lastViewCmd = viewCmd;
viewCmd = (ViewCommand)cmd;
if (StartViewCommand != null)
StartViewCommand(this, EventArgs.Empty);
if (viewCmd.SavePrevious)
{
GraphicViewManager.Instance.SavePreviousActiveView();
//System.Console.WriteLine("SavePrevious");
}
if (viewCmd.IsInteractive)
mainFrm.ScenePanel.Cursor = viewCmd.Cursor;
else
{
viewCmd.Run(GraphicViewManager.Instance.ActiveView);
GraphicViewManager.Instance.updateView(false);
if (EndViewCommand != null)
EndViewCommand(this, new EndViewCommandArgs(viewCmd));
if (lastViewCmd == SelectionCommand)
viewCmd = SelectionCommand;
else
{
//if (lastViewCmd.SavePrevious && viewCmd != Commands.View.ZoomPrevious.Instance)
//{
// GraphicViewManager.Instance.SavePreviousActiveView();
// System.Console.WriteLine("SavePrevious");
//}
//viewCmd = lastViewCmd;
Execute("select");
}
if (StartViewCommand != null)
StartViewCommand(this, EventArgs.Empty);
}
}
else if (cmd is ModelCommand)
{
if (modelCmd == null)
{
// Por el momento funcionan en el mismo hilo, por lo que al terminar la
// llamada a Run se puede asignar modelCmd = null y services = null
modelCmd = (ModelCommand)cmd;
modelCmd.Cancel = false;
try
{
if (StartModelCommand != null)
StartModelCommand(this, EventArgs.Empty);
modelCmd.Run(services = new CommandServices(this));
}
catch (CancelCommandException) { Model.Model.Instance.Undo.Rollback(); }
catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Controller.Execute: {0}", ex.Message); }
finally
{
endModelCommand();
}
}
else
{
System.Windows.Forms.MessageBox.Show(Culture.Get("ModelCmdAlreadyExecuting"), Culture.Get("ActionNotPossibleTitle"), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
return false;
}
}
return true;
}
static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Windows Vista Virtualization Problem FIX if (fixVistaVirtualizationError()) { return; } // End of Windows Vista FIX Utility.Updater updater = new Utility.Updater(); if (updater.Update()) { return; } System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture; Splash.Show(3000); Model.Model model = Model.Model.Instance; Controller.Controller controller = Controller.Controller.Instance; View.GraphicViewManager view = View.GraphicViewManager.Instance; model.Reset(); //TestModel(model); using (MainFrm frm = new MainFrm()) { frm.Show(); try { view.InitializeGraphics(frm.ScenePanel, frm); controller.MainFrm = frm; if (args.Length > 0) { controller.LoadModel(args[0]); } //////// TESTS ///////////// //TestView(view); //model.AbstractCases.Add(new Canguro.Model.Load.AnalysisCase("aCase1")); //Model.Load.AnalysisCase anc = model.AbstractCases[0] as Model.Load.AnalysisCase; //if (anc != null) //{ // Model.Load.StaticCaseProps props = anc.Properties as Model.Load.StaticCaseProps; // if (props != null) // { // List<Model.Load.StaticCaseFactor> list = props.Loads; // list.Add(new Canguro.Model.Load.StaticCaseFactor(model.ActiveLoadCase)); // props.Loads = list; // } //} ////////// END TESTS ///////////// Application.Run(frm); // Model.Model.Instance.Save(); controller.Execute("cancel"); updater.CancelDownload(); updater.InstallUpdate(); } #if DEBUG catch (View.NoDirectXSupportException ex) { MessageBox.Show(Culture.Get("strDirectXFatalError") + "\n" + ex.ToString(), Culture.Get("strFatalError"), MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Microsoft.DirectX.DirectXException ex) { MessageBox.Show(Culture.Get("strDirectXFatalError") + "\n" + ex.ToString(), Culture.Get("strFatalError"), MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (NotSupportedException ex) { MessageBox.Show(ex.Message, Culture.Get("strFatalError"), MessageBoxButtons.OK, MessageBoxIcon.Error); } #else catch (View.NoDirectXSupportException ex) { MessageBox.Show(Culture.Get("strDirectXFatalError"), Culture.Get("strFatalError"), MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Microsoft.DirectX.DirectXException ex) { MessageBox.Show(Culture.Get("strDirectXFatalError"), Culture.Get("strFatalError"), MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (NotSupportedException ex) { MessageBox.Show(ex.Message, Culture.Get("strFatalError"), MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show(ex.Message, Culture.Get("strFatalError"), MessageBoxButtons.OK, MessageBoxIcon.Error); } #endif } }