Exemple #1
0
		/// <summary>
		/// Creates a new instance of <see cref="MainForm">MainForm</see> window.
		/// </summary>
		public MainForm()
		{
			//
			// Required for Windows Form Designer support
			//
			
			_compositionBoxPositionInArea = new Point(0,0);

			InitializeComponent();

			_composition = new CompositionManager();

			_prevMouse = new Point(0,0);

			_sourceCursor = new Cursor(GetType(), "Source.cur");
			_targetCursor = new Cursor(GetType(), "Target.cur");

			// create dialogs
			_modelDialog = new ModelDialog();
			_connectionDialog = new ConnectionDialog();
			_aboutBox = new AboutBox();
			_runProperties = new RunProperties();
			_runBox = new RunBox();

			menuRegisterExtensions.Checked = Utils.AreFileExtensionsRegistered( Application.ExecutablePath );
		}
		private static void RunApplication( object data )
		{
			try
			{
				bool verboseOff = (bool)( (object[]) data )[0];
				string oprFilename = (string) ( (object[]) data )[1];

				// check whether opr file exists
				if( oprFilename==null )
				{
					Console.WriteLine( "Error: -r switch was not specified." );
					_exitCode = 3;
					return;
				}

				FileInfo fileInfo = new FileInfo( oprFilename );
				if( !fileInfo.Exists )
				{
					Console.WriteLine( "Error: cannot find input file "+oprFilename );
					_exitCode = 4;
					return;
				}


				// open OPR
				CompositionManager composition = new CompositionManager();

				if( !verboseOff )
					Console.WriteLine( "Loading project file "+fileInfo.FullName+"..." );
				composition.LoadFromFile( fileInfo.FullName );


				// prepare listeners
				if( !verboseOff )
					Console.WriteLine( "Preparing listener(s)..." );
				ArrayList listOfListeners = new ArrayList();

				// logfile listener
				if( composition.LogToFile!=null && composition.LogToFile!="" )
				{
					// get composition file's directory to logfile is saved in same directory
					string logFileName = Utils.GetFileInfo( fileInfo.DirectoryName, composition.LogToFile ).FullName;
					LogFileListener logFileListener = new LogFileListener( composition.ListenedEventTypes, logFileName );
					listOfListeners.Add( logFileListener );
				}

				// console listener
				if( !verboseOff )
				{
					ConsoleListener consoleListener = new ConsoleListener( composition.ListenedEventTypes );
					listOfListeners.Add( consoleListener );
				}

				// create proxy listener
				ProxyListener proxyListener = new ProxyListener();
				proxyListener.Initialize( listOfListeners );

				// run simulation
				if( !verboseOff )
					Console.WriteLine( "Starting composition run..." );
				composition.Run( proxyListener, true );

				if( !verboseOff )
					Console.WriteLine( "Closing composition..." );
				composition.Release();

				_exitCode = 0;
			}
			catch( Exception e )
			{
				Console.WriteLine( "Exception occured: " + e.ToString() );
				_exitCode = -2;
				return;
			}
		}
Exemple #3
0
        private Brush GetFillBrush(CompositionManager.EEditorMode mode)
		{
            if (mode == CompositionManager.EEditorMode.RunButNotReloaded)
                return new SolidBrush(Color.LightGray);

			if( _modelID == CompositionManager.TriggerModelID )
			{
				// trigger has different color
				if( _isMoving )
					return( new SolidBrush(Color.SteelBlue) );
				else
					return( new SolidBrush(Color.SkyBlue) );
			}			

			if( _isMoving )
				return( new SolidBrush(Color.Goldenrod) );
			else
				return( new SolidBrush(Color.Yellow) );
		}
Exemple #4
0
		/// <summary>
		/// Draws this model's rectangle into specified <see cref="Graphics">Graphics</see> object.
		/// </summary>
		/// <param name="displacement">Displacement of composition box in whole composition area.</param>
		/// <param name="g"><see cref="Graphics">Graphics</see> where rectangle should be drawn.</param>
		public void Draw(Point displacement, CompositionManager.EEditorMode mode, Graphics g)
		{
			Rectangle rectToDraw = Rect;
			rectToDraw.X -= displacement.X;
			rectToDraw.Y -= displacement.Y;

			Region fillRegion = new Region(rectToDraw);	
		
			g.FillRegion( GetFillBrush(mode), fillRegion );
			g.DrawRectangle( _rectanglePen, rectToDraw);
			g.DrawString( _modelID, _font, Brushes.Black,rectToDraw);
		}
		/// <summary>
		/// Populates this dialog with specific composition.
		/// </summary>
		/// <param name="composition">Composition to be used for dialog.</param>
		/// <param name="initialTriggerInvokeTime">
		/// If <c>true</c>, the <see cref="CompositionManager.TriggerInvokeTime">CompositionManager.TriggerInvokeTime</see>
		/// is set to latest overlapping time of time horizons of all models. Typically this is used
		/// when this dialog is showed for the first time.</param>
		public void PopulateDialog( CompositionManager composition, bool initialTriggerInvokeTime )
		{
			_composition = composition;			

			Debug.Assert( _composition.HasTrigger() );
			Debug.Assert( _composition.Models.Count > 1 );

			// fill dialog according to composition
			if( _composition.LogToFile == null )
			{
				checkBoxLogToFile.Checked = false;
				textLogToFile.Text = "CompositionRun.log";
			}
			else
			{
				checkBoxLogToFile.Checked = true;
				textLogToFile.Text = _composition.LogToFile;
			}

			for( int i=0; i<(int)EventType.NUM_OF_EVENT_TYPES; i++ )
				checkboxesEventTypes[i].Checked = _composition.ListenedEventTypes[i];

			if( initialTriggerInvokeTime )
			{
				buttonTimeLatestOverlapping_Click(null, null);
			}
			else
			{
				textTriggerInvokeTime.Text = _composition.TriggerInvokeTime.ToString( );
			}

			checkBoxEventsToListbox.Checked = _composition.ShowEventsInListbox;

			checkBoxNoMultithreading.Checked = _composition.RunInSameThread;

			runIt = false;
		}
Exemple #6
0
		/// <summary>
		/// Populates this dialog with specified composition and proxy listener.
		/// </summary>
		/// <param name="composition">Composition which simulation is to be run.</param>
		/// <param name="listener">Listener which is used for monitoring simulation.</param>
		/// <remarks>
		/// Simulation is fired after this dialog is showed. That's because if
		/// simulation runs in same thread we won't be able to show it another way.
		/// We determine whether simulation runs in same thread using
		/// <see cref="CompositionManager.RunInSameThread">CompositionManager.RunInSameThread</see> property.
		/// </remarks>
		public void PopuplateDialog( CompositionManager composition, IListener listener )
		{
			_composition        = composition;
			_listener           = listener;			
			_finished           = false;
			_started            = false;
			buttonClose.Enabled = !composition.RunInSameThread;
			buttonStop.Enabled  = !composition.RunInSameThread;			

			progressBarRun.Value = 0;
			progressBarRun.Enabled = true;

			labelInfo.Text = "Running...";

			listViewEvents.Items.Clear();
		}
		/// <summary>
		/// Draw connection (i.e. line with triangle) to specific graphics object.
		/// </summary>
		/// <param name="windowPosition">Position of window described by graphics object in composition area.</param>
		/// <param name="g">Graphics where connection should be drawn.</param>		
        public void Draw(Point windowPosition, CompositionManager.EEditorMode mode, Graphics g)
		{
			float startX = _providingModel.GetMidPoint().X;
			float startY = _providingModel.GetMidPoint().Y ;
			float endX   = _acceptingModel.GetMidPoint().X;
			float endY   = _acceptingModel.GetMidPoint().Y;

			// calculate triangle point in area points and store them internally
			_trianglePoints = GetTrianglePoints( startX, startY, endX, endY );

			// recalculate trinagle points so they correspond to window and can be draw
			Point[] windowTrianglePoints = new Point[3];
			for( int i=0; i<3; i++ )
			{
				windowTrianglePoints[i].X = _trianglePoints[i].X - windowPosition.X;
				windowTrianglePoints[i].Y = _trianglePoints[i].Y - windowPosition.Y;
			}

			// modify start and end so they correspond to window
			startX -= windowPosition.X;
			startY -= windowPosition.Y;
			endX -= windowPosition.X;
			endY -= windowPosition.Y;

            Pen pen = linePen;
            Pen penTriangle = Pens.Red;
            Brush brush = Brushes.Blue;

            if (mode == CompositionManager.EEditorMode.RunButNotReloaded)
            {
                pen = linePenDisabled;
                brush = Brushes.LightGray;
                penTriangle = Pens.Gray;
            }

			g.DrawLine(pen, startX, startY, endX, endY);
			
			// we draw the triangle only the link is at least 10 pixels
			if( Math.Abs(startX-endX) + Math.Abs(startY-endY) > 10 )
			{
                g.FillPolygon( brush, windowTrianglePoints, System.Drawing.Drawing2D.FillMode.Alternate);
                g.DrawPolygon( penTriangle, windowTrianglePoints);
			}
		}