public virtual void Dispose()
 {
     VertexOffsets.Dispose();
     VertexIndices.Dispose();
     EdgeFlags.Dispose();
     Triangles.Dispose();
 }
Exemple #2
0
        private Vector ComputeIncrementalDelta(EdgeFlags edgeFlags)
        {
            Vector vector = new Vector();
            double num1   = this.ScrollTimer.Interval.TotalSeconds / 2.0 / this.SceneView.Zoom;
            double num2   = this.SceneView.Artboard.ActualWidth * num1;
            double num3   = this.SceneView.Artboard.ActualHeight * num1;

            if ((edgeFlags & EdgeFlags.Left) != EdgeFlags.None)
            {
                vector.X -= num2;
            }
            else if ((edgeFlags & EdgeFlags.Right) != EdgeFlags.None)
            {
                vector.X += num2;
            }
            if ((edgeFlags & EdgeFlags.Top) != EdgeFlags.None)
            {
                vector.Y -= num3;
            }
            else if ((edgeFlags & EdgeFlags.Bottom) != EdgeFlags.None)
            {
                vector.Y += num3;
            }
            return(vector);
        }
Exemple #3
0
        public Point SnapPoint(Point point, EdgeFlags edgeFlags)
        {
            if (!this.IsEnabled)
            {
                return(point);
            }
            Point snappedPoint = point;

            if (this.IsStarted && this.DesignerContext.ArtboardOptionsModel.SnapToSnapLines && edgeFlags != EdgeFlags.None)
            {
                if (this.toolContext.View.ViewModel.ActiveSceneInsertionPoint == null)
                {
                    return(point);
                }
                SceneElement sceneElement = this.toolContext.View.ViewModel.ActiveSceneInsertionPoint.SceneElement;
                if (sceneElement.IsViewObjectValid)
                {
                    Vector vector = this.SnapRect(new Rect(this.toolContext.View.TransformPointFromRoot(sceneElement, point), new Size(0.0, 0.0)), sceneElement, new Vector(0.0, 0.0), edgeFlags);
                    snappedPoint = point + vector;
                }
            }
            else if (this.DesignerContext.ArtboardOptionsModel.SnapToGrid)
            {
                this.SnapPointToGrid(point, out snappedPoint);
            }
            return(snappedPoint);
        }
Exemple #4
0
 public NavGraphEdge(int src, int dst, double cost,
                     EdgeFlags flags,
                     int id = -1) : base(src, dst, cost)
 {
     SelfFlags = flags;
     TheIDofIntersectingEntity = id;
 }
Exemple #5
0
        /// <summary>
        /// This method is used for getting EdgeData from object that should be EdgeData.
        /// </summary>
        /// <param name="objectToParse">object that need to be transformed to EdgeData</param>
        /// <returns>EdgeData that was in form of object</returns>
        public static EdgeData ParseEdgeData(Object objectToParse)
        {
            if (objectToParse == null)
            {
                return(null);
            }

            if (objectToParse is Dictionary <String, Object> )
            {
                Dictionary <String, Object> dictionaryRepresentationOfObject = (Dictionary <String, Object>)objectToParse;

                if (dictionaryRepresentationOfObject.ContainsKey(FLAGS) &&
                    dictionaryRepresentationOfObject.ContainsKey(SEMANTIC) &&
                    dictionaryRepresentationOfObject.ContainsKey(DATA))
                {
                    int       flagsValue = (int)dictionaryRepresentationOfObject[FLAGS];
                    EdgeType  semnatic   = (EdgeType)dictionaryRepresentationOfObject[SEMANTIC];
                    EdgeFlags flags      = (EdgeFlags)flagsValue;
                    Object    data       = ObjectWrapper.ParseObjectWrapper(dictionaryRepresentationOfObject[DATA]);
                    EdgeData  edgeData   = new EdgeData(semnatic, flags, data);
                    return(edgeData);
                }
                else
                {
                    throw new Exception("Object is not formated right!");
                }
            }
            else
            {
                throw new Exception("Object is not formated right!");
            }
        }
Exemple #6
0
 /// <summary>
 /// Initializes a new instance of the <c>Face3D</c> class.
 /// </summary>
 /// <param name="firstVertex">3d face <see cref="Vector3">first vertex</see>.</param>
 /// <param name="secondVertex">3d face <see cref="Vector3">second vertex</see>.</param>
 /// <param name="thirdVertex">3d face <see cref="Vector3">third vertex</see>.</param>
 /// <param name="fourthVertex">3d face <see cref="Vector3">fourth vertex</see>.</param>
 public Face3d(Vector3 firstVertex, Vector3 secondVertex, Vector3 thirdVertex, Vector3 fourthVertex)
     : base(EntityType.Face3D, DxfObjectCode.Face3d)
 {
     this.firstVertex  = firstVertex;
     this.secondVertex = secondVertex;
     this.thirdVertex  = thirdVertex;
     this.fourthVertex = fourthVertex;
     this.edgeFlags    = EdgeFlags.Visibles;
 }
Exemple #7
0
 /// <summary>
 /// Calculate edge flags from type attribute values.
 /// </summary>
 /// <param name="isPermanent"></param>
 /// <param name="saveParentNodes"></param>
 /// <returns></returns>
 public EdgeFlags CalculateEdgeFlags(bool isPermanent, bool saveParentNodes)
 {
     EdgeFlags edgeFlags = EdgeFlags.None;
     if (isPermanent)
     {
         edgeFlags |= EdgeFlags.Permanent;
     }
     if (saveParentNodes)
     {
         edgeFlags |= EdgeFlags.StoreParentNodes;
     }
     return edgeFlags;
 }
Exemple #8
0
 /// <summary>
 /// Initializes a new instance of the <c>Face3D</c> class.
 /// </summary>
 public Face3d()
     : base(DxfObjectCode.Face3D)
 {
     this.firstVertex  = Vector3f.Zero;
     this.secondVertex = Vector3f.Zero;
     this.thirdVertex  = Vector3f.Zero;
     this.fourthVertex = Vector3f.Zero;
     this.edgeFlags    = EdgeFlags.Visibles;
     this.layer        = Layer.Default;
     this.color        = AciColor.ByLayer;
     this.lineType     = LineType.ByLayer;
     this.xData        = new Dictionary <ApplicationRegistry, XData>();
 }
Exemple #9
0
 public DesignTimeSizeAdorner(AdornerSet adornerSet, EdgeFlags edgeFlags)
     : base(adornerSet, edgeFlags)
 {
     if (this.EdgeFlags == EdgeFlags.Left || this.EdgeFlags == EdgeFlags.Right)
     {
         this.type = DesignTimeAdornerType.Width;
     }
     else if (this.EdgeFlags == EdgeFlags.Top || this.EdgeFlags == EdgeFlags.Bottom)
     {
         this.type = DesignTimeAdornerType.Height;
     }
     else
     {
         this.type = DesignTimeAdornerType.Corner;
     }
 }
Exemple #10
0
        private void SnapDragPosition(Point dragCurrentPosition)
        {
            if (!this.ActiveSceneInsertionPoint.SceneNode.IsViewObjectValid || this.ActiveSceneInsertionPoint.SceneElement.Visual == null)
            {
                return;
            }
            SceneView    activeView = this.ActiveView;
            Point        location   = activeView.TransformPoint((IViewObject)activeView.HitTestRoot, this.ActiveSceneInsertionPoint.SceneElement.Visual, this.dragStartPosition);
            Point        point      = activeView.TransformPoint((IViewObject)activeView.HitTestRoot, this.ActiveSceneInsertionPoint.SceneElement.Visual, dragCurrentPosition);
            EdgeFlags    edgeFlags  = (EdgeFlags)((location.X <= point.X ? 4 : 1) | (location.Y <= point.Y ? 8 : 2));
            Rect         rect       = new Rect(location, new Size(0.0, 0.0));
            Vector       offset     = dragCurrentPosition - this.dragStartPosition;
            SceneElement container  = this.EditingElement == null || !this.EditingElement.IsViewObjectValid ? this.ActiveSceneInsertionPoint.SceneElement : this.EditingElement.VisualElementAncestor ?? (SceneElement)this.EditingElement;
            Vector       vector     = this.ToolBehaviorContext.SnappingEngine.SnapRect(rect, container, offset, edgeFlags);

            this.dragCurrentPosition = dragCurrentPosition + vector;
        }
Exemple #11
0
        public void StartScroll(Point startPoint, Point currentPoint)
        {
            this.startPosition   = startPoint;
            this.currentPosition = currentPoint;
            Artboard artboard = this.SceneView.Artboard;

            this.mousePosition    = Mouse.GetPosition((IInputElement)artboard);
            this.artboardBoundary = new Rect(0.0, 0.0, artboard.ActualWidth, artboard.ActualHeight);
            if (this.Behavior.ShouldMotionlessAutoScroll(this.mousePosition, this.artboardBoundary))
            {
                this.scrollDirection = this.ComputeScrollDirection();
                this.ScrollTimer.Start();
            }
            else
            {
                this.ScrollTimer.Stop();
            }
        }
Exemple #12
0
        public static bool SkipAdorner(EdgeFlags edgeFlags, Matrix matrix, Rect bounds)
        {
            System.Windows.Size ofTransformedRect = Adorner.GetSizeOfTransformedRect(bounds, matrix);
            double num1 = 5.0;
            double num2 = 12.5;

            if (ofTransformedRect.Width < num1 && ofTransformedRect.Height < num1)
            {
                if (edgeFlags != EdgeFlags.BottomRight)
                {
                    return(true);
                }
            }
            else if (edgeFlags != EdgeFlags.Top && edgeFlags != EdgeFlags.Bottom && (edgeFlags != EdgeFlags.Right && ofTransformedRect.Width < num1) || edgeFlags != EdgeFlags.Left && edgeFlags != EdgeFlags.Right && (edgeFlags != EdgeFlags.Bottom && ofTransformedRect.Height < num1) || ((edgeFlags == EdgeFlags.Top || edgeFlags == EdgeFlags.Bottom) && (ofTransformedRect.Width < num2 && ofTransformedRect.Width >= num1) || (edgeFlags == EdgeFlags.Left || edgeFlags == EdgeFlags.Right) && (ofTransformedRect.Height < num2 && ofTransformedRect.Height >= num1)))
            {
                return(true);
            }
            return(false);
        }
Exemple #13
0
        private Rect OffsetRect(Rect rect, Vector offset, EdgeFlags edgeFlags)
        {
            if (!rect.IsEmpty)
            {
                switch (edgeFlags & EdgeFlags.LeftOrRight)
                {
                case EdgeFlags.Left:
                    rect.X    += offset.X;
                    rect.Width = Math.Max(0.0, rect.Width - offset.X);
                    break;

                case EdgeFlags.Right:
                    rect.Width = Math.Max(0.0, rect.Width + offset.X);
                    break;

                case EdgeFlags.LeftOrRight:
                    rect.X += offset.X;
                    break;
                }
                switch (edgeFlags & EdgeFlags.TopOrBottom)
                {
                case EdgeFlags.Top:
                    rect.Y     += offset.Y;
                    rect.Height = Math.Max(0.0, rect.Height - offset.Y);
                    break;

                case EdgeFlags.Bottom:
                    rect.Height = Math.Max(0.0, rect.Height + offset.Y);
                    break;

                case EdgeFlags.TopOrBottom:
                    rect.Y += offset.Y;
                    break;
                }
            }
            return(rect);
        }
Exemple #14
0
 /// <summary>
 /// Removes an edge from an instance of <see cref="EdgeFlags"/>.
 /// </summary>
 /// <param name="edges">A set of edges.</param>
 /// <param name="dir">The direction to remove.</param>
 public static void RemoveEdge(ref EdgeFlags edges, Direction dir)
 {
     edges &= (EdgeFlags)(~(1 << (int)dir));
 }
Exemple #15
0
 /// <summary>
 /// Flips the set of edges in an instance of <see cref="EdgeFlags"/>.
 /// </summary>
 /// <param name="edges">An existing set of edges.</param>
 public static void FlipEdges(ref EdgeFlags edges)
 {
     edges ^= EdgeFlags.All;
 }
Exemple #16
0
 /// <summary>
 /// Determines whether an instance of <see cref="EdgeFlags"/> includes an edge in a specified direction.
 /// </summary>
 /// <param name="edges">A set of edges.</param>
 /// <param name="dir">The direction to check for an edge.</param>
 /// <returns>A value indicating whether the set of edges contains an edge in the specified direction.</returns>
 public static bool IsConnected(ref EdgeFlags edges, Direction dir)
 {
     return((edges & (EdgeFlags)(1 << (int)dir)) != EdgeFlags.None);
 }
Exemple #17
0
 public RadialScaleAdorner(BrushTransformAdornerSet adornerSet, EdgeFlags edgeFlags)
     : base(adornerSet, edgeFlags)
 {
 }
Exemple #18
0
 /// <summary>
 /// Adds an edge in a specified direction to an instance of <see cref="EdgeFlags"/>.
 /// </summary>
 /// <param name="edges">An existing set of edges.</param>
 /// <param name="dir">The direction to add.</param>
 public static void AddEdge(ref EdgeFlags edges, Direction dir)
 {
     edges |= (EdgeFlags)(1 << (int)dir);
 }
Exemple #19
0
        public static void DrawSizeAdorner(DrawingContext drawingContext, Point anchorPoint, EdgeFlags edgeFlags, Matrix matrix, Brush brush, Pen pen, Rect bounds, AdornerRenderLocation location)
        {
            if (SizeAdorner.SkipAdorner(edgeFlags, matrix, bounds))
            {
                return;
            }
            Vector vector1 = new Vector(1.0, 0.0) * matrix;
            Vector vector2 = new Vector(0.0, 1.0) * matrix;

            vector1.Normalize();
            vector2.Normalize();
            double num1    = matrix.Determinant < 0.0 ? -1.0 : 1.0;
            Point  point   = anchorPoint;
            Matrix matrix1 = new Matrix(0.0, 1.0 * num1, -1.0 * num1, 0.0, 0.0, 0.0);
            Matrix matrix2 = new Matrix(0.0, -1.0 * num1, 1.0 * num1, 0.0, 0.0, 0.0);
            Vector vector3 = vector1 * matrix1;
            Vector vector4 = vector2 * matrix2;
            Vector vector5 = vector1 * 8.0;
            Vector vector6 = vector2 * 8.0;

            if (location == AdornerRenderLocation.Inside)
            {
                switch (edgeFlags & EdgeFlags.TopOrBottom)
                {
                case EdgeFlags.None:
                    vector1      = vector4;
                    anchorPoint -= 0.5 * (5.0 - pen.Thickness) * vector2;
                    point       += vector2 * 0.5 * 8.0;
                    break;

                case EdgeFlags.Top:
                    vector2      = vector3;
                    anchorPoint += 0.5 * pen.Thickness * vector2;
                    point       += vector2 * 8.0;
                    break;

                case EdgeFlags.Bottom:
                    vector2      = vector3;
                    anchorPoint -= (5.0 - 0.5 * pen.Thickness) * vector2;
                    break;
                }
                switch (edgeFlags & EdgeFlags.LeftOrRight)
                {
                case EdgeFlags.None:
                    anchorPoint -= 0.5 * (5.0 - pen.Thickness) * vector1;
                    point       += vector1 * 0.5 * 8.0;
                    break;

                case EdgeFlags.Left:
                    anchorPoint += 0.5 * pen.Thickness * vector1;
                    point       += vector1 * 8.0;
                    break;

                case EdgeFlags.Right:
                    anchorPoint -= (5.0 - 0.5 * pen.Thickness) * vector1;
                    break;
                }
            }
            else
            {
                switch (edgeFlags & EdgeFlags.TopOrBottom)
                {
                case EdgeFlags.None:
                    vector1      = vector4;
                    anchorPoint -= 0.5 * (5.0 - pen.Thickness) * vector2;
                    point       += vector2 * 0.5 * 8.0;
                    break;

                case EdgeFlags.Top:
                    vector2      = vector3;
                    anchorPoint -= (5.0 - 0.5 * pen.Thickness) * vector2;
                    break;

                case EdgeFlags.Bottom:
                    vector2      = vector3;
                    anchorPoint += 0.5 * pen.Thickness * vector2;
                    point       += vector2 * 8.0;
                    break;
                }
                switch (edgeFlags & EdgeFlags.LeftOrRight)
                {
                case EdgeFlags.None:
                    anchorPoint -= 0.5 * (5.0 - pen.Thickness) * vector1;
                    point       += vector1 * 0.5 * 8.0;
                    break;

                case EdgeFlags.Left:
                    anchorPoint -= (5.0 - 0.5 * pen.Thickness) * vector1;
                    break;

                case EdgeFlags.Right:
                    anchorPoint += 0.5 * pen.Thickness * vector1;
                    point       += vector1 * 8.0;
                    break;
                }
            }
            StreamGeometry        streamGeometry1        = new StreamGeometry();
            StreamGeometryContext streamGeometryContext1 = streamGeometry1.Open();

            streamGeometryContext1.BeginFigure(point - vector5, true, true);
            streamGeometryContext1.LineTo(point - vector5 - vector6, false, false);
            streamGeometryContext1.LineTo(point - vector6, false, false);
            streamGeometryContext1.LineTo(point, false, false);
            streamGeometryContext1.Close();
            streamGeometry1.Freeze();
            drawingContext.DrawGeometry((Brush)Brushes.Transparent, (Pen)null, (System.Windows.Media.Geometry)streamGeometry1);
            double                num2                   = 5.0 - pen.Thickness;
            Vector                vector7                = vector1 * num2;
            Vector                vector8                = vector2 * num2;
            StreamGeometry        streamGeometry2        = new StreamGeometry();
            StreamGeometryContext streamGeometryContext2 = streamGeometry2.Open();

            streamGeometryContext2.BeginFigure(anchorPoint, true, true);
            streamGeometryContext2.LineTo(anchorPoint + vector8, true, false);
            streamGeometryContext2.LineTo(anchorPoint + vector7 + vector8, true, false);
            streamGeometryContext2.LineTo(anchorPoint + vector7, true, false);
            streamGeometryContext2.Close();
            streamGeometry2.Freeze();
            drawingContext.DrawGeometry(brush, pen, (System.Windows.Media.Geometry)streamGeometry2);
        }
Exemple #20
0
 public SizeAdorner(AdornerSet adornerSet, EdgeFlags edgeFlags)
     : base(adornerSet, edgeFlags)
 {
 }
Exemple #21
0
 public RotateAdorner(AdornerSet adornerSet, EdgeFlags edgeFlags)
     : base(adornerSet, edgeFlags)
 {
 }
Exemple #22
0
        /// <summary>
        /// Decompose the actual polyface mesh faces in <see cref="Point">points</see> (one vertex polyface mesh face),
        /// <see cref="Line">lines</see> (two vertexes polyface mesh face) and <see cref="Face3d">3d faces</see> (three or four vertexes polyface mesh face).
        /// </summary>
        /// <returns>A list of <see cref="Face3d">3d faces</see> that made up the polyface mesh.</returns>
        public List <EntityObject> Explode()
        {
            List <EntityObject> entities = new List <EntityObject>();

            foreach (PolyfaceMeshFace face in this.Faces)
            {
                if (face.VertexIndexes.Length == 1)
                {
                    Point point = new Point
                    {
                        Location      = this.Vertexes[Math.Abs(face.VertexIndexes[0]) - 1].Location,
                        Color         = this.Color,
                        IsVisible     = this.IsVisible,
                        Layer         = this.Layer,
                        LineType      = this.LineType,
                        LineTypeScale = this.LineTypeScale,
                        Lineweight    = this.Lineweight,
                        XData         = this.XData
                    };
                    entities.Add(point);
                    continue;
                }
                if (face.VertexIndexes.Length == 2)
                {
                    Line line = new Line
                    {
                        StartPoint    = this.Vertexes[Math.Abs(face.VertexIndexes[0]) - 1].Location,
                        EndPoint      = this.Vertexes[Math.Abs(face.VertexIndexes[1]) - 1].Location,
                        Color         = this.Color,
                        IsVisible     = this.IsVisible,
                        Layer         = this.Layer,
                        LineType      = this.LineType,
                        LineTypeScale = this.LineTypeScale,
                        Lineweight    = this.Lineweight,
                        XData         = this.XData
                    };
                    entities.Add(line);
                    continue;
                }

                EdgeFlags edgeVisibility = EdgeFlags.Visibles;

                int indexV1 = face.VertexIndexes[0];
                int indexV2 = face.VertexIndexes[1];
                int indexV3 = face.VertexIndexes[2];
                // Polyface mesh faces are made of 3 or 4 vertexes, we will repeat the third vertex if the face vertexes is three
                int indexV4 = face.VertexIndexes.Length == 3 ? face.VertexIndexes[2] : face.VertexIndexes[3];

                if (indexV1 < 0)
                {
                    edgeVisibility = edgeVisibility | EdgeFlags.First;
                }
                if (indexV2 < 0)
                {
                    edgeVisibility = edgeVisibility | EdgeFlags.Second;
                }
                if (indexV3 < 0)
                {
                    edgeVisibility = edgeVisibility | EdgeFlags.Third;
                }
                if (indexV4 < 0)
                {
                    edgeVisibility = edgeVisibility | EdgeFlags.Fourth;
                }

                Vector3 v1 = this.Vertexes[Math.Abs(indexV1) - 1].Location;
                Vector3 v2 = this.Vertexes[Math.Abs(indexV2) - 1].Location;
                Vector3 v3 = this.Vertexes[Math.Abs(indexV3) - 1].Location;
                Vector3 v4 = this.Vertexes[Math.Abs(indexV4) - 1].Location;

                Face3d face3d = new Face3d
                {
                    FirstVertex   = v1,
                    SecondVertex  = v2,
                    ThirdVertex   = v3,
                    FourthVertex  = v4,
                    EdgeFlags     = edgeVisibility,
                    Color         = this.Color,
                    IsVisible     = this.IsVisible,
                    Layer         = this.Layer,
                    LineType      = this.LineType,
                    LineTypeScale = this.LineTypeScale,
                    Lineweight    = this.Lineweight,
                    XData         = this.XData
                };

                entities.Add(face3d);
            }
            return(entities);
        }
Exemple #23
0
        public Vector SnapRect(Rect rect, SceneElement container, Vector offset, EdgeFlags edgeFlags, double baselineOffset)
        {
            if (!this.IsEnabled || !this.IsStarted)
            {
                return(new Vector());
            }
            Vector vector1             = new Vector();
            Vector constraintDirection = new Vector();

            if (this.DesignerContext.ArtboardOptionsModel.SnapToSnapLines)
            {
                vector1 = this.snapLineEngine.SnapRect(rect, offset, edgeFlags, baselineOffset, out constraintDirection);
            }
            if (this.DesignerContext.ArtboardOptionsModel.SnapToGrid && (constraintDirection.X == 0.0 || constraintDirection.Y == 0.0))
            {
                Point[] pointArray = new Point[4]
                {
                    rect.TopLeft,
                    rect.TopRight,
                    rect.BottomRight,
                    rect.BottomLeft
                };
                EdgeFlags[] edgeFlagsArray = new EdgeFlags[4]
                {
                    EdgeFlags.TopLeft,
                    EdgeFlags.TopRight,
                    EdgeFlags.BottomRight,
                    EdgeFlags.BottomLeft
                };
                EdgeFlags edgeFlags1 = edgeFlags;
                if (edgeFlags == EdgeFlags.Left || edgeFlags == EdgeFlags.Right)
                {
                    edgeFlags1 |= EdgeFlags.TopOrBottom;
                }
                else if (edgeFlags == EdgeFlags.Top || edgeFlags == EdgeFlags.Bottom)
                {
                    edgeFlags1 |= EdgeFlags.LeftOrRight;
                }
                double num1    = double.PositiveInfinity;
                double num2    = double.PositiveInfinity;
                Vector vector2 = new Vector();
                for (int index = 0; index < 4; ++index)
                {
                    if ((edgeFlagsArray[index] & edgeFlags1) == edgeFlagsArray[index])
                    {
                        Point point = this.toolContext.View.TransformPointToRoot(container, pointArray[index]) + offset;
                        Point snappedPoint;
                        if (this.SnapPointToGrid(point, out snappedPoint))
                        {
                            Vector vector3 = snappedPoint - point;
                            if (constraintDirection.Y != 0.0)
                            {
                                vector3.X = 0.0;
                            }
                            if (constraintDirection.X != 0.0)
                            {
                                vector3.Y = 0.0;
                            }
                            double num3 = Math.Abs(vector3.X);
                            if (num3 > 0.0 && num3 < num1)
                            {
                                num1      = num3;
                                vector2.X = vector3.X;
                            }
                            double num4 = Math.Abs(vector3.Y);
                            if (num4 > 0.0 && num4 < num2)
                            {
                                num2      = num4;
                                vector2.Y = vector3.Y;
                            }
                        }
                    }
                }
                vector1 += vector2;
            }
            return(vector1);
        }
Exemple #24
0
 public Vector SnapRect(Rect rect, SceneElement container, Vector offset, EdgeFlags edgeFlags)
 {
     return(this.SnapRect(rect, container, offset, edgeFlags, double.NaN));
 }
Exemple #25
0
        public Vector SnapRect(Rect rect, Vector offset, EdgeFlags edgeFlags, double baselineOffset, out Vector constraintDirection)
        {
            constraintDirection = new Vector();
            if (!this.IsStarted || this.container == null)
            {
                return(new Vector());
            }
            offset = this.toolContext.View.TransformVectorFromRoot((SceneElement)this.container, offset);
            rect   = this.OffsetRect(rect, offset, edgeFlags);
            double          scaledSnapThreshold = this.ScaledSnapThreshold;
            double          adjustment1         = 0.0;
            List <SnapLine> snapLineList1_1     = (List <SnapLine>)null;

            if ((edgeFlags & EdgeFlags.Left) != EdgeFlags.None)
            {
                snapLineList1_1 = this.FindNearestSnapLines(rect.TopLeft, rect.BottomLeft, SnapLineLocation.Minimum, SnapLineOrientation.Vertical, scaledSnapThreshold, out adjustment1);
            }
            double          adjustment2     = 0.0;
            List <SnapLine> snapLineList2_1 = (List <SnapLine>)null;

            if ((edgeFlags & EdgeFlags.Right) != EdgeFlags.None)
            {
                snapLineList2_1 = this.FindNearestSnapLines(rect.TopRight, rect.BottomRight, SnapLineLocation.Maximum, SnapLineOrientation.Vertical, scaledSnapThreshold, out adjustment2);
            }
            double          chosenAdjustment1;
            List <SnapLine> list            = this.ChooseSnapLines(snapLineList1_1, adjustment1, snapLineList2_1, adjustment2, out chosenAdjustment1);
            double          adjustment3     = 0.0;
            List <SnapLine> snapLineList1_2 = (List <SnapLine>)null;

            if ((edgeFlags & EdgeFlags.Top) != EdgeFlags.None)
            {
                snapLineList1_2 = this.FindNearestSnapLines(rect.TopLeft, rect.TopRight, SnapLineLocation.Minimum, SnapLineOrientation.Horizontal, scaledSnapThreshold, out adjustment3);
            }
            double          adjustment4     = 0.0;
            List <SnapLine> snapLineList2_2 = (List <SnapLine>)null;

            if ((edgeFlags & EdgeFlags.Bottom) != EdgeFlags.None)
            {
                snapLineList2_2 = this.FindNearestSnapLines(rect.BottomLeft, rect.BottomRight, SnapLineLocation.Maximum, SnapLineOrientation.Horizontal, scaledSnapThreshold, out adjustment4);
            }
            double          chosenAdjustment2;
            List <SnapLine> snapLineList1_3 = this.ChooseSnapLines(snapLineList1_2, adjustment3, snapLineList2_2, adjustment4, out chosenAdjustment2);

            if (!double.IsNaN(baselineOffset) && (edgeFlags & EdgeFlags.TopOrBottom) == EdgeFlags.TopOrBottom)
            {
                double          adjustment5      = 0.0;
                List <SnapLine> nearestSnapLines = this.FindNearestSnapLines(new Point(rect.Left, rect.Top + baselineOffset), new Point(rect.Right, rect.Top + baselineOffset), SnapLineLocation.Baseline, SnapLineOrientation.Horizontal, scaledSnapThreshold, out adjustment5);
                snapLineList1_3 = this.ChooseSnapLines(snapLineList1_3, chosenAdjustment2, nearestSnapLines, adjustment5, out chosenAdjustment2);
            }
            List <SnapLine> snapLines = new List <SnapLine>();

            if (snapLineList1_3 != null)
            {
                snapLines.AddRange((IEnumerable <SnapLine>)snapLineList1_3);
            }
            if (list != null)
            {
                snapLines.AddRange((IEnumerable <SnapLine>)list);
            }
            rect = this.OffsetRect(rect, new Vector(chosenAdjustment1, chosenAdjustment2), edgeFlags);
            this.snapLineRenderer.ReplaceSnapLines(this.targetElement, rect, snapLines);
            if (snapLineList1_3 != null && snapLineList1_3.Count > 0)
            {
                constraintDirection = list == null || list.Count <= 0 ? this.toolContext.View.TransformVectorToRoot((SceneElement)this.container, new Vector(1.0, 0.0)) : new Vector(1.0, 1.0);
            }
            else if (list != null && list.Count > 0)
            {
                constraintDirection = this.toolContext.View.TransformVectorToRoot((SceneElement)this.container, new Vector(0.0, 1.0));
            }
            return(this.toolContext.View.TransformVectorToRoot((SceneElement)this.container, new Vector(chosenAdjustment1, chosenAdjustment2)));
        }
        /// <summary>
        /// Initial generation of the contours
        /// </summary>
        /// <param name="spanReference">A referecne to the span to start walking from.</param>
        /// <param name="flags">An array of flags determinining </param>
        /// <param name="points">The vertices of a contour.</param>
        private void WalkContour(CompactSpanReference spanReference, EdgeFlags[] flags, List<ContourVertex> points)
        {
            Direction dir = Direction.West;

            //find the first direction that has a connection
            while (!EdgeFlagsHelper.IsConnected(ref flags[spanReference.Index], dir))
                dir++;

            Direction startDir = dir;
            int startIndex = spanReference.Index;

            Area area = areas[startIndex];

            //TODO make the max iterations value a variable
            int iter = 0;
            while (++iter < 40000)
            {
                // this direction is connected
                if (EdgeFlagsHelper.IsConnected(ref flags[spanReference.Index], dir))
                {
                    // choose the edge corner
                    bool isBorderVertex;
                    bool isAreaBorder = false;

                    int px = spanReference.X;
                    int py = GetCornerHeight(spanReference, dir, out isBorderVertex);
                    int pz = spanReference.Y;

                    switch (dir)
                    {
                        case Direction.West:
                            pz++;
                            break;
                        case Direction.North:
                            px++;
                            pz++;
                            break;
                        case Direction.East:
                            px++;
                            break;
                    }

                    RegionId r = RegionId.Null;
                    CompactSpan s = this[spanReference];
                    if (s.IsConnected(dir))
                    {
                        int dx = spanReference.X + dir.GetHorizontalOffset();
                        int dy = spanReference.Y + dir.GetVerticalOffset();
                        int di = cells[dx + dy * width].StartIndex + CompactSpan.GetConnection(ref s, dir);
                        r = spans[di].Region;
                        if (area != areas[di])
                            isAreaBorder = true;
                    }

                    // apply flags if neccessary
                    if (isBorderVertex)
                        r = RegionId.WithFlags(r, RegionFlags.VertexBorder);

                    if (isAreaBorder)
                        r = RegionId.WithFlags(r, RegionFlags.AreaBorder);

                    //save the point
                    points.Add(new ContourVertex(px, py, pz, r));

                    EdgeFlagsHelper.RemoveEdge(ref flags[spanReference.Index], dir);	// remove visited edges
                    dir = dir.NextClockwise();			// rotate clockwise
                }
                else
                {
                    //get a new cell(x, y) and span index(i)
                    int di = -1;
                    int dx = spanReference.X + dir.GetHorizontalOffset();
                    int dy = spanReference.Y + dir.GetVerticalOffset();

                    CompactSpan s = this[spanReference];
                    if (s.IsConnected(dir))
                    {
                        CompactCell dc = cells[dx + dy * width];
                        di = dc.StartIndex + CompactSpan.GetConnection(ref s, dir);
                    }

                    if (di == -1)
                    {
                        // shouldn't happen
                        // TODO if this shouldn't happen, this check shouldn't be necessary.
                        throw new InvalidOperationException("Something went wrong");
                    }

                    spanReference = new CompactSpanReference(dx, dy, di);
                    dir = dir.NextCounterClockwise(); // rotate counterclockwise
                }

                if (startIndex == spanReference.Index && startDir == dir)
                    break;
            }
        }
Exemple #27
0
 /// <summary>
 /// Creates new instance of EdgeData type
 /// </summary>
 /// <param name="semantic">Edge semantic</param>
 /// <param name="flags">Edge flags</param>
 /// <param name="data">Optional edge data</param>
 public EdgeData(EdgeType semantic, EdgeFlags flags, object data)
 {
     Semantic = semantic;
     Data     = data;
     Flags    = flags;
 }
Exemple #28
0
 /// <summary>
 /// Creates new instance of EdgeData type
 /// </summary>
 /// <param name="semantic">Edge semantic</param>
 /// <param name="data">Optional edge data</param>
 public EdgeData(EdgeType semantic, object data)
 {
     Semantic = semantic;
     Data     = data;
     Flags    = EdgeFlags.None;
 }
 protected AnchorPointAdorner(AdornerSet adornerSet, EdgeFlags edgeFlags)
     : base(adornerSet)
 {
     this.edgeFlags = edgeFlags;
 }
        /// <summary>
        /// Builds a set of <see cref="Contour"/>s around the generated regions. Must be called after regions are generated.
        /// </summary>
        /// <param name="maxError">The maximum allowed deviation in a simplified contour from a raw one.</param>
        /// <param name="maxEdgeLength">The maximum edge length.</param>
        /// <param name="buildFlags">Flags that change settings for the build process.</param>
        /// <returns>A <see cref="ContourSet"/> containing one contour per region.</returns>
        public ContourSet BuildContourSet(float maxError, int maxEdgeLength, ContourBuildFlags buildFlags)
        {
            BBox3 contourSetBounds = bounds;
            if (borderSize > 0)
            {
                //remove offset
                float pad = borderSize * cellSize;
                contourSetBounds.Min.X += pad;
                contourSetBounds.Min.Z += pad;
                contourSetBounds.Max.X -= pad;
                contourSetBounds.Max.Z -= pad;
            }

            int contourSetWidth = width - borderSize * 2;
            int contourSetLength = length - borderSize * 2;

            int maxContours = Math.Max(maxRegions, 8);
            var contours = new List<Contour>(maxContours);

            EdgeFlags[] flags = new EdgeFlags[spans.Length];

            //Modify flags array by using the CompactHeightfield data
            //mark boundaries
            for (int z = 0; z < length; z++)
            {
                for (int x = 0; x < width; x++)
                {
                    //loop through all the spans in the cell
                    CompactCell c = cells[x + z * width];
                    for (int i = c.StartIndex, end = c.StartIndex + c.Count; i < end; i++)
                    {
                        CompactSpan s = spans[i];

                        //set the flag to 0 if the region is a border region or null.
                        if (s.Region.IsNull || RegionId.HasFlags(s.Region, RegionFlags.Border))
                        {
                            flags[i] = 0;
                            continue;
                        }

                        //go through all the neighboring cells
                        for (var dir = Direction.West; dir <= Direction.South; dir++)
                        {
                            //obtain region id
                            RegionId r = RegionId.Null;
                            if (s.IsConnected(dir))
                            {
                                int dx = x + dir.GetHorizontalOffset();
                                int dz = z + dir.GetVerticalOffset();
                                int di = cells[dx + dz * width].StartIndex + CompactSpan.GetConnection(ref s, dir);
                                r = spans[di].Region;
                            }

                            //region ids are equal
                            if (r == s.Region)
                            {
                                //res marks all the internal edges
                                EdgeFlagsHelper.AddEdge(ref flags[i], dir);
                            }
                        }

                        //flags represents all the nonconnected edges, edges that are only internal
                        //the edges need to be between different regions
                        EdgeFlagsHelper.FlipEdges(ref flags[i]);
                    }
                }
            }

            var verts = new List<ContourVertex>();
            var simplified = new List<ContourVertex>();

            for (int z = 0; z < length; z++)
            {
                for (int x = 0; x < width; x++)
                {
                    CompactCell c = cells[x + z * width];
                    for (int i = c.StartIndex, end = c.StartIndex + c.Count; i < end; i++)
                    {
                        //flags is either 0000 or 1111
                        //in other words, not connected at all
                        //or has all connections, which means span is in the middle and thus not an edge.
                        if (flags[i] == EdgeFlags.None || flags[i] == EdgeFlags.All)
                        {
                            flags[i] = EdgeFlags.None;
                            continue;
                        }

                        var spanRef = new CompactSpanReference(x, z, i);
                        RegionId reg = this[spanRef].Region;
                        if (reg.IsNull || RegionId.HasFlags(reg, RegionFlags.Border))
                            continue;

                        //reset each iteration
                        verts.Clear();
                        simplified.Clear();

                        //Walk along a contour, then build it
                        WalkContour(spanRef, flags, verts);
                        Contour.Simplify(verts, simplified, maxError, maxEdgeLength, buildFlags);
                        Contour.RemoveDegenerateSegments(simplified);
                        Contour contour = new Contour(simplified, reg, areas[i], borderSize);

                        if (!contour.IsNull)
                            contours.Add(contour);
                    }
                }
            }

            //Check and merge bad contours
            for (int i = 0; i < contours.Count; i++)
            {
                Contour cont = contours[i];

                //Check if contour is backwards
                if (cont.Area2D < 0)
                {
                    //Find another contour to merge with
                    int mergeIndex = -1;
                    for (int j = 0; j < contours.Count; j++)
                    {
                        if (i == j)
                            continue;

                        //Must have at least one vertex, the same region ID, and be going forwards.
                        Contour contj = contours[j];
                        if (contj.Vertices.Length != 0 && contj.RegionId == cont.RegionId && contj.Area2D > 0)
                        {
                            mergeIndex = j;
                            break;
                        }
                    }

                    //Merge if found.
                    if (mergeIndex != -1)
                    {
                        contours[mergeIndex].MergeWith(cont);
                        contours.RemoveAt(i);
                        i--;
                    }
                }
            }

            return new ContourSet(contours, contourSetBounds, contourSetWidth, contourSetLength);
        }
 public bool TestFlags(EdgeFlags flagsToTest)
 {
     return((this.edgeFlags & flagsToTest) != EdgeFlags.None);
 }
Exemple #32
0
 /// <summary>
 /// Initializes a new instance of the <c>Face3D</c> class.
 /// </summary>
 /// <param name="firstVertex">3d face <see cref="Vector3d">first vertex</see>.</param>
 /// <param name="secondVertex">3d face <see cref="Vector3d">second vertex</see>.</param>
 /// <param name="thirdVertex">3d face <see cref="Vector3d">third vertex</see>.</param>
 /// <param name="fourthVertex">3d face <see cref="Vector3d">fourth vertex</see>.</param>
 public Face3d(Vector3d firstVertex, Vector3d secondVertex, Vector3d thirdVertex, Vector3d fourthVertex)
     : base(DxfObjectCode.Face3D)
 {
     this.firstVertex = firstVertex;
     this.secondVertex = secondVertex;
     this.thirdVertex = thirdVertex;
     this.fourthVertex = fourthVertex;
     this.edgeFlags = EdgeFlags.Visibles;
     this.layer = Layer.Default;
     this.color = AciColor.ByLayer;
     this.lineType = LineType.ByLayer;
     this.xData = new Dictionary<ApplicationRegistry, XData>();
 }
Exemple #33
0
 private Point GetAnchorPointAdornerPosition(EdgeFlags edgeFlags, Matrix matrix)
 {
     return(new BrushRotateAdorner(this.ActiveAdorner.AdornerSet, edgeFlags).GetAnchorPoint(matrix));
 }