예제 #1
0
        public void On_State_Changed(SimpleCAD_State newState)
        {
            if (m_bDontUpdateState)
            {
                return;
            }

            // Deep clone state.
            // If you dont clone state then SetState will set existing geometry objects as SimpleCAD children geometry.
            //
            // Bug:
            // 1. Create line and save this drawing
            // 2. Restart SimpleCAD and open the drawing.
            // 3. Select line and move grip point 2 times, so you will have 2 changes.
            // 4. Click Undo.
            // 5. Click Undo again - the drawing doesnt return in original state.
            // Instead its the last state - when grip point was moved the second time.
            //
            // Its result of using the same line instance in SimpleCAD as in Document.States collection.
            // When grip was moved changes are applied to Document.States collection.
            // Correct way - make copy of State and use it as a new state. So SimpleCAD and Document.States will
            // have independent copies of the same state.
            SimpleCAD_State clonedState = null;

            if (newState != null)
            {
                clonedState = Utils.DeepClone <SimpleCAD_State>(newState);
            }

            this.SetState(clonedState);
        }
예제 #2
0
        //=============================================================================
        private SimpleCAD_State GetState()
        {
            SimpleCAD_State curentState = new SimpleCAD_State(
                m_geometries,
                m_OffsetVector,
                GeometryToCreate,
                AxesColor,
                AxesThickness,
                AxesLength,
                AxesTextSize,
                Scale);

            // return copy of state
            // dont return curent state, because when call method SimpleCAD._ClearAll m_geometries array will be empty in returned value
            return(Utils.DeepClone <SimpleCAD_State>(curentState));
        }
예제 #3
0
        //=============================================================================
        private bool SetState(SimpleCAD_State state)
        {
            _ClearAll();

            bool bInvalidate = false;

            if (state == null)
            {
                if (this.IsEnabled)
                {
                    this.IsEnabled = false;
                    bInvalidate    = true;
                }
            }
            else if (!this.IsEnabled)
            {
                this.IsEnabled = true;
                bInvalidate    = true;
            }

            //
            // call InvalidateVisual, it will call OnRender() and redraw background
            if (bInvalidate)
            {
                InvalidateVisual();
            }

            if (state == null)
            {
                return(false);
            }

            m_OffsetVector = state.OffsetVector;

            if (state.Geometries != null)
            {
                foreach (ICadGeometry geom in state.Geometries)
                {
                    GeometryWraper gw = geom.GetGeometryWrapper() as GeometryWraper;
                    if (gw != null)
                    {
                        gw.Owner = this;
                    }
                    else
                    {
                        gw = new GeometryWraper(this, geom);
                    }

                    if (gw != null)
                    {
                        AddVisualChild(gw);
                        AddLogicalChild(gw);

                        m_geometries.Add(gw);
                    }
                }
            }

            AxesColor     = state.AxesColor;
            AxesThickness = state.AxesThickness;
            AxesLength    = state.AxesLength;
            AxesTextSize  = state.AxesTextSize;

            Scale = state.Scale;

            GeometryToCreate = state.GeometryToCreate;

            UpdatePlot();

            return(true);
        }