예제 #1
0
        /// <summary>
        /// calculates all offsets for the msc
        /// </summary>
        /// <param name="drawDestination">actual drawing area</param>
        /// <param name="worksheet">worksheet sizes of the drawing area</param>
        public void CalcOffsets(Graphics drawDestination, Worksheet worksheet)
        {
            IEnumerator enumerator;
            float 	instanceSpace, 		// horizontal space for every instance
                    instanceOffset,		// x position of the first instance
                 	sumMargin=0,		// margin summation to affact each instance space
                 	xSize, 				// width of the drawing area without margins
                    ySize;				// height of the drawing area without margins

            CalcProcessMargins();
            enumerator = processes.GetEnumerator();
            for(uint i=0;i<processes.Count;i++){		//calculate summation of all margins
                enumerator.MoveNext();
                sumMargin +=((Process)enumerator.Current).LeftMargin+((Process)enumerator.Current).RightMargin;
            }
            this.mAutoWidth = (sumMargin + processes.Count * 150);
            if (Output.AutosizeOutputWidth == true){
                worksheet.SetWorksheetWidth((int)this.mAutoWidth);
            }
            xSize = (worksheet.Width - worksheet.LeftMargin) - worksheet.RightMargin;	// calculate width of drawing area
            ySize = worksheet.GetWorksheetHeight();	// calculate height of drawing area
            Trace.WriteLine(DateTime.Now.TimeOfDay + " ySize: " + ySize.ToString());

            instanceSpace = (xSize-(INLINE_OFFSET*2)-sumMargin)/processes.Count;		// calculate the available space for each instance
            instanceOffset = INLINE_OFFSET+instanceSpace/2 + worksheet.LeftMargin;		// calculate the x positon of first instance
            HeadHeight = headLine.GetHeight(drawDestination, xSize);
            enumerator.Reset();
            sumMargin = 0;
            for(uint i=0;i<processes.Count;i++){										// calculate the x position of each instance
                enumerator.MoveNext();
                sumMargin +=((Process)enumerator.Current).LeftMargin;
                ((Process)enumerator.Current).XPos = sumMargin + instanceOffset + i * instanceSpace;
                sumMargin +=((Process)enumerator.Current).RightMargin;
            }
            MSCItem.ItemLayoutSize = new SizeF(instanceSpace,(ySize-this.YProcessOffset)-20);			// set the max size of msc items
            mProcessNameHeight=0;
            mInstanceNameHeight=0;
            this.CalcProcessesNameHeight(drawDestination);
            this.mYProcessName = worksheet.TopMargin + this.GetProcessesDescriptionHeight(drawDestination) + this.HeadHeight;	// set the verical position of instance name
            this.YProcessOffset = this.mYProcessName + mInstanceNameHeight+20; 			// set the vertical offset for first msc item
            if (instanceSpace < GEM_MIN_INSTANCE_SPACE)									// check min horizontal space for instances
                this.generatorResult = GeneratorResult.InstanceSpaceToSmall;			// diagram can not be drawn
            else
                this.generatorResult = GeneratorResult.OK;								// insantce horizontal space ok
        }
예제 #2
0
        /// <summary>
        /// calculates all offsets and line heights for the msc
        /// </summary>
        /// <param name="drawDestination">actual drawing area</param>
        /// <param name="worksheet">worksheet sizes of the drawing area</param>
        /// <param name="font">font used in the msc</param>
        public void CalcLineHights(Graphics drawDestination, Worksheet worksheet, Font font)
        {
            IEnumerator enumerator;
            uint 	line=0;				// msc line counter
            float 	instanceSpace, 		// horizontal space for every instance
                    instanceOffset,		// x position of the first instance
                 	sumMargin=0,		// margin summation to affact each instance space
                 	xSize, 				// width of the drawing area without margins
                    ySize;				// height of the drawing area without margins

            CalcProcessMargins();
            enumerator = processes.GetEnumerator();
            for(uint i=0;i<processes.Count;i++){		//calculate summation of all margins
                enumerator.MoveNext();
                sumMargin +=((Process)enumerator.Current).LeftMargin+((Process)enumerator.Current).RightMargin;
            }
            this.mAutoWidth = (sumMargin + processes.Count * 150);
            if (Output.AutosizeOutputWidth == true){
                worksheet.SetWorksheetWidth((int)this.mAutoWidth);
            }
            xSize = (worksheet.Width - worksheet.LeftMargin) - worksheet.RightMargin;	// calculate width of drawing area
            ySize = worksheet.GetWorksheetHeight();	// calculate height of drawing area

            instanceSpace = (xSize-(INLINE_OFFSET*2)-sumMargin)/processes.Count;		// calculate the available space for each instance
            if (instanceSpace < GEM_MIN_INSTANCE_SPACE){
                generatorResult = GeneratorResult.InstanceSpaceToSmall;
            }
            else{
                generatorResult = GeneratorResult.OK;
            }
            instanceOffset = INLINE_OFFSET+instanceSpace/2 + worksheet.LeftMargin;		// calculate the x positon of first instance
            HeadHeight = headLine.GetHeight(drawDestination, xSize);
            enumerator.Reset();
            sumMargin = 0;
            for(uint i=0;i<processes.Count;i++){										// calculate the x position of each instance
                enumerator.MoveNext();
                sumMargin +=((Process)enumerator.Current).LeftMargin;
                ((Process)enumerator.Current).XPos = sumMargin + instanceOffset + i * instanceSpace;
                sumMargin +=((Process)enumerator.Current).RightMargin;
            }
            MSCItem.ItemFont = font;
            MSCItem.ItemLayoutSize = new SizeF(instanceSpace,(ySize-this.YProcessOffset)-20);			// set the max size of msc items
            mProcessNameHeight=0;
            mInstanceNameHeight=0;
            this.CalcProcessesNameHeight(drawDestination);
            this.mYProcessName = worksheet.TopMargin + this.GetProcessesDescriptionHeight(drawDestination) + this.HeadHeight;	// set the verical position of instance name
            this.YProcessOffset = this.mYProcessName + mInstanceNameHeight+20; 			// set the vertical offset for first msc item
            if (mLines>0){
                mDiagramLines = new DiagramLine[mLines+2];
                enumerator = items.GetEnumerator();
                for(uint i=0;i<items.Count;i++){										// store the maximum line height of each msc line
                    enumerator.MoveNext();
                    if (enumerator.Current is State)
                    {
                        float xPosMin = GetInstanceXPos(processes.Count-1);
                        float xPosMax = 0;

                        for(int j=0; j<processes.Count; j++){
                            if(((State)enumerator.Current).IsUsedProcess(j)){
                                xPosMin = Math.Min(xPosMin,GetInstanceXPos(j));
                                xPosMax = Math.Max(xPosMax,GetInstanceXPos(j));
                            }
                        }
                        mDiagramLines[((State)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((State)enumerator.Current).Line].Height,((State)enumerator.Current).GetHeight(drawDestination,xPosMin,xPosMax));
                        line = ((State)enumerator.Current).Line;
                    }
                    if (enumerator.Current is MSCEnd)
                    {
                        mDiagramLines[((MSCEnd)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((MSCEnd)enumerator.Current).Line].Height,((MSCEnd)enumerator.Current).GetHeight(drawDestination));
                        line = ((MSCEnd)enumerator.Current).Line;
                    }
                    if (enumerator.Current is MeasureStart)
                    {
                        mDiagramLines[((MeasureStart)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((MeasureStart)enumerator.Current).Line].Height,((MeasureStart)enumerator.Current).GetHeight(drawDestination));
                        line = ((MeasureStart)enumerator.Current).Line;
                    }
                    if (enumerator.Current is MeasureStop)
                    {
                        mDiagramLines[((MeasureStop)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((MeasureStop)enumerator.Current).Line].Height,((MeasureStop)enumerator.Current).GetHeight(drawDestination));
                        line = ((MeasureStop)enumerator.Current).Line;
                    }
                    if (enumerator.Current is MeasureBeginn)
                    {
                        mDiagramLines[((MeasureBeginn)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((MeasureBeginn)enumerator.Current).Line].Height,((MeasureBeginn)enumerator.Current).GetHeight(drawDestination));
                        line = ((MeasureBeginn)enumerator.Current).Line;
                    }
                    if (enumerator.Current is MeasureEnd)
                    {
                        mDiagramLines[((MeasureEnd)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((MeasureEnd)enumerator.Current).Line].Height,((MeasureEnd)enumerator.Current).GetHeight(drawDestination));
                        line = ((MeasureEnd)enumerator.Current).Line;
                    }
                    if (enumerator.Current is TimerBegin)
                    {
                        mDiagramLines[((TimerBegin)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((TimerBegin)enumerator.Current).Line].Height,((TimerBegin)enumerator.Current).GetHeight(drawDestination));
                        line = ((TimerBegin)enumerator.Current).Line;
                    }
                    if (enumerator.Current is TimerEnd)
                    {
                        mDiagramLines[((TimerEnd)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((TimerEnd)enumerator.Current).Line].Height,((TimerEnd)enumerator.Current).GetHeight(drawDestination));
                        line = ((TimerEnd)enumerator.Current).Line;
                    }
                    if (enumerator.Current is TimeoutBegin)
                    {
                        mDiagramLines[((TimeoutBegin)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((TimeoutBegin)enumerator.Current).Line].Height,((TimeoutBegin)enumerator.Current).GetHeight(drawDestination));
                        line = ((TimeoutBegin)enumerator.Current).Line;
                    }
                    if (enumerator.Current is TimeoutEnd)
                    {
                        mDiagramLines[((TimeoutEnd)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((TimeoutEnd)enumerator.Current).Line].Height,((TimeoutEnd)enumerator.Current).GetHeight(drawDestination));
                        line = ((TimeoutEnd)enumerator.Current).Line;
                    }
                    if (enumerator.Current is TimeoutStop)
                    {
                        mDiagramLines[((TimeoutStop)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((TimeoutStop)enumerator.Current).Line].Height,((TimeoutStop)enumerator.Current).GetHeight(drawDestination));
                        line = ((TimeoutStop)enumerator.Current).Line;
                    }
                    if (enumerator.Current is TimeOut)
                    {
                        mDiagramLines[((TimeOut)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((TimeOut)enumerator.Current).Line].Height,((TimeOut)enumerator.Current).GetHeight(drawDestination));
                        line = ((TimeOut)enumerator.Current).Line;
                    }
                    if (enumerator.Current is StopTimer)
                    {
                        mDiagramLines[((StopTimer)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((StopTimer)enumerator.Current).Line].Height,((StopTimer)enumerator.Current).GetHeight(drawDestination));
                        line = ((StopTimer)enumerator.Current).Line;
                    }
                    if (enumerator.Current is SetTimer)
                    {
                        mDiagramLines[((SetTimer)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((SetTimer)enumerator.Current).Line].Height,((SetTimer)enumerator.Current).GetHeight(drawDestination));
                        line = ((SetTimer)enumerator.Current).Line;
                    }
                    if (enumerator.Current is Comment)
                    {
                        if (((Comment)enumerator.Current).Position == CommentPos.OverAll){
                            mDiagramLines[((Comment)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((Comment)enumerator.Current).Line].Height,((Comment)enumerator.Current).GetHeight(drawDestination,GetInstanceXPos(((Comment) enumerator.Current).Process), GetInstanceXPos(0),GetInstanceXPos(processes.Count-1), MSC.LeftMargin + ((Process)processes[0]).LeftRand, MSC.RightMargin + ((Process)processes[processes.Count-1]).RightRand));
                        }
                        else{
                            mDiagramLines[((Comment)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((Comment)enumerator.Current).Line].Height,((Comment)enumerator.Current).GetHeight(drawDestination,GetInstanceXPos(((Comment) enumerator.Current).Process), worksheet.LeftMargin,worksheet.Width-worksheet.RightMargin, MSC.LeftMargin + ((Process)processes[0]).LeftRand, MSC.RightMargin + ((Process)processes[processes.Count-1]).RightRand));
                        }
                        line = ((Comment)enumerator.Current).Line;
                    }
                    if (enumerator.Current is LineComment)
                    {
                        mDiagramLines[((LineComment)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((LineComment)enumerator.Current).Line].Height,((LineComment)enumerator.Current).GetHeight(drawDestination));
                        line = ((LineComment)enumerator.Current).Line;
                    }
                    if (enumerator.Current is Task)
                    {
                        mDiagramLines[((Task)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((Task)enumerator.Current).Line].Height,((Task)enumerator.Current).GetHeight(drawDestination));
                        line = ((Task)enumerator.Current).Line;
                    }
                    if (enumerator.Current is mscElements.Message)
                    {
                        mDiagramLines[((mscElements.Message)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((mscElements.Message)enumerator.Current).Line].Height,((mscElements.Message)enumerator.Current).GetHeight(drawDestination, GetInstanceXPos(((mscElements.Message)enumerator.Current).MessageSource), GetInstanceXPos(((mscElements.Message)enumerator.Current).MessageDestination)));
                        line = ((mscElements.Message)enumerator.Current).Line;
                    }
                    if (enumerator.Current is Mark)
                    {
                        mDiagramLines[((Mark)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((Mark)enumerator.Current).Line].Height,((Mark)enumerator.Current).GetHeight(drawDestination));
                        line = ((Mark)enumerator.Current).Line;
                    }
                    if (enumerator.Current is FoundMessage)
                    {
                        mDiagramLines[((FoundMessage)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((FoundMessage)enumerator.Current).Line].Height,((FoundMessage)enumerator.Current).GetHeight(drawDestination));
                        line = ((FoundMessage)enumerator.Current).Line;
                    }
                    if (enumerator.Current is LostMessage)
                    {
                        mDiagramLines[((LostMessage)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((LostMessage)enumerator.Current).Line].Height,((LostMessage)enumerator.Current).GetHeight(drawDestination));
                        line = ((LostMessage)enumerator.Current).Line;
                    }
                    if (enumerator.Current is ProcessStop)
                    {
                        mDiagramLines[((ProcessStop)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((ProcessStop)enumerator.Current).Line].Height,((ProcessStop)enumerator.Current).GetHeight(drawDestination));
                        line = ((ProcessStop)enumerator.Current).Line;
                    }
                    if (enumerator.Current is ProcessCreate)
                    {
                        mDiagramLines[((ProcessCreate)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((ProcessCreate)enumerator.Current).Line].Height,((ProcessCreate)enumerator.Current).GetHeight(drawDestination, GetInstanceXPos(((ProcessCreate)enumerator.Current).Source), GetInstanceXPos(((ProcessCreate)enumerator.Current).Destination)));
                        line = ((ProcessCreate)enumerator.Current).Line;
                    }
                    if (enumerator.Current is ProcessRegion)
                    {
                        mDiagramLines[((ProcessRegion)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((ProcessRegion)enumerator.Current).Line].Height,((ProcessRegion)enumerator.Current).GetHeight(drawDestination));
                        line = ((ProcessRegion)enumerator.Current).Line;
                    }
                    if (enumerator.Current is Reference)
                    {
                        mDiagramLines[((Reference)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((Reference)enumerator.Current).Line].Height,((Reference)enumerator.Current).GetHeight(drawDestination, GetInstanceXPos(((Reference)enumerator.Current).ProcessBeginn), GetInstanceXPos(((Reference)enumerator.Current).ProcessEnd)));
                        line = ((Reference)enumerator.Current).Line;
                    }
                    if (enumerator.Current is InLineBeginn)
                    {
                        mDiagramLines[((InLineBeginn)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((InLineBeginn)enumerator.Current).Line].Height,((InLineBeginn)enumerator.Current).GetHeight(drawDestination));
                        line = ((InLineBeginn)enumerator.Current).Line;
                    }
                    if (enumerator.Current is InLineEnd)
                    {
                        mDiagramLines[((InLineEnd)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((InLineEnd)enumerator.Current).Line].Height,((InLineEnd)enumerator.Current).GetHeight(drawDestination));
                        line = ((InLineEnd)enumerator.Current).Line;
                    }
                    if (enumerator.Current is InLineSeparator)
                    {
                        mDiagramLines[((InLineSeparator)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((InLineSeparator)enumerator.Current).Line].Height,((InLineSeparator)enumerator.Current).GetHeight(drawDestination));
                        line = ((InLineSeparator)enumerator.Current).Line;
                    }
                    if (enumerator.Current is InLineText)
                    {
                        mDiagramLines[((InLineText)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((InLineText)enumerator.Current).Line].Height,((InLineText)enumerator.Current).GetHeight(drawDestination, ((Process)processes[((InLineText)enumerator.Current).ProcessBeginn]).LeftRand));
                        line = ((InLineText)enumerator.Current).Line;
                    }
                    if (enumerator.Current is MessageBegin)
                    {
                        mDiagramLines[((MessageBegin)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((MessageBegin)enumerator.Current).Line].Height,((MessageBegin)enumerator.Current).GetHeight(drawDestination, GetInstanceXPos(((MessageBegin)enumerator.Current).MessageSource), GetInstanceXPos(((MessageBegin)enumerator.Current).MessageDestination)));
                        line = ((MessageBegin)enumerator.Current).Line;
                    }
                    if (enumerator.Current is MessageEnd)
                    {
                        mDiagramLines[((MessageEnd)enumerator.Current).Line].Height = Math.Max(mDiagramLines[((MessageEnd)enumerator.Current).Line].Height,((MessageEnd)enumerator.Current).GetHeight(drawDestination));
                        line = ((MessageEnd)enumerator.Current).Line;
                    }
                    if (enumerator.Current is NewPage)
                    {
                        mDiagramLines[((NewPage)enumerator.Current).Line].Height = ((NewPage)enumerator.Current).GetHeight();
                        line = ((NewPage)enumerator.Current).Line;
                    }
                }
            }
            if (instanceSpace < GEM_MIN_INSTANCE_SPACE)
                this.generatorResult = GeneratorResult.InstanceSpaceToSmall;
            else
                this.generatorResult = GeneratorResult.OK;
        }