the line class for the segment of grid line, it inherits from Line2D class
Inheritance: Line2D
コード例 #1
0
        /// <summary>
        /// the "regeneration" step: if there're only 2 segments existing in one joint and they're in the same line,
        /// delete one seg will cause the other been deleted automatically
        /// </summary>
        /// <param name="segLine2D">
        /// the to-be-automatically-deleted segment
        /// </param>
        /// <param name="removeList">
        /// the referred to-be-deleted list of the segments
        /// </param>
        /// <returns>
        /// returns the operation result: if there's no "last" segment in the deletion operation, return true; otherwise false
        /// </returns>
        private void MimicRecursiveDelete(ref bool canRemove, SegmentLine2D segLine2D, List <SegmentLine2D> removeList)
        {
            // the "regeneration" step: if there're only 2 segments existing in one joint
            // and they're in the same line, delete one seg will cause the other
            // been deleted automatically
            // get conjoint U line segments
            List <SegmentLine2D> removeSegments = new List <SegmentLine2D>();

            m_drawing.GetConjointSegments(segLine2D, removeSegments);

            // there's no isolated segment need to be removed automatically
            if (null == removeSegments || 0 == removeSegments.Count)
            {
                // didn't "remove last segment of the curtain grid line", all the operations are valid. so return true
                return;
            }

            // there're conjoint segments need to be removed automatically
            // add the segments to removeList first, and compute whether other segments need to be
            // removed automatically because of the deletion of this newly removed segment
            if (true == segLine2D.Removed)
            {
                foreach (SegmentLine2D seg in removeSegments)
                {
                    MimicRemoveSegment(ref canRemove, seg, removeList);

                    if (false == canRemove)
                    {
                        return;
                    }
                    // recursive calling
                    MimicRecursiveDelete(ref canRemove, seg, removeList);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// remove the segment from the grid line
        /// </summary>
        /// <param name="canRemove">
        /// the returned result value, indicates whether the segment can be removed (is NOT the last segment)
        /// </param>
        /// <param name="seg">
        /// the to-be-removed segment
        /// </param>
        /// <param name="removeList">
        /// the referred to-be-deleted list of the segments
        /// </param>
        private void MimicRemoveSegment(ref bool canRemove, SegmentLine2D seg, List <SegmentLine2D> removeList)
        {
            int gridLineIndex = seg.GridLineIndex;
            int segIndex      = seg.SegmentIndex;

            if (-1 != gridLineIndex && -1 != segIndex)
            {
                // update the gridline2d and segmentline2d data
                GridLine2D grid;
                if (true == seg.IsUSegment)
                {
                    grid = m_drawing.UGridLines2D[gridLineIndex];
                }
                else
                {
                    grid = m_drawing.VGridLines2D[gridLineIndex];
                }

                // the last segment of the grid line
                int existingNumber = grid.Segments.Count - grid.RemovedNumber;
                if (1 == existingNumber)
                {
                    canRemove = false;
                    return;
                }

                grid.RemovedNumber++;
                SegmentLine2D seg2D = grid.Segments[segIndex];
                seg2D.Removed           = true;
                grid.Segments[segIndex] = seg2D;

                removeList.Add(seg2D);
            }
        }
コード例 #3
0
 /// <summary>
 /// copy constructor
 /// </summary>
 /// <param name="segLine2D">
 /// the source segment line 2D
 /// </param>
 public SegmentLine2D(SegmentLine2D segLine2D)
     : base((Line2D)segLine2D)
 {
     m_removed       = segLine2D.Removed;
     m_isolated      = segLine2D.Isolated;
     m_segmentIndex  = segLine2D.SegmentIndex;
     m_gridLineIndex = segLine2D.GridLineIndex;
 }
コード例 #4
0
        /// <summary>
        /// a simulative "Delete Segment" operation before real deletion
        /// as we may occur some situations that prevent us to delete the specific segment
        /// for example, delete the specific segment will make some other segments to be deleted automatically (the "conjoint" ones)
        /// and the "automatically deleted" segment is the last segment of its parent grid line
        /// in this situation, we should prevent deleting that specific segment and rollback all the simulative deletion
        /// </summary>
        /// <param name="removeList">
        /// the refferred to-be-removed list, in the simulative deletion operation, all the suitable (not the last segment) segments will
        /// be added to that list
        /// </param>
        private void MimicRemoveSegments(ref bool canRemove, List <SegmentLine2D> removeList)
        {
            // the currently operated is a U segment
            if (-1 != m_drawing.SelectedUIndex)
            {
                GridLine2D    gridLine2D = m_drawing.UGridLines2D[m_drawing.SelectedUIndex];
                SegmentLine2D segLine2D  = gridLine2D.Segments[m_drawing.SelectedUSegmentIndex];

                // the to-be-deleted segment is the last one of the grid line, it's not allowed to delete it
                int existingNumber = gridLine2D.Segments.Count - gridLine2D.RemovedNumber;
                if (1 == existingNumber)
                {
                    canRemove = false;
                    return;
                }

                // simulative deletion
                gridLine2D.RemovedNumber++;
                segLine2D.Removed = true;
                gridLine2D.Segments[m_drawing.SelectedUSegmentIndex] = segLine2D;
                removeList.Add(segLine2D);
                // the "regeneration" step: if there're only 2 segments existing in one joint and they're in the same line, delete one seg will cause the other
                // been deleted automatically
                MimicRecursiveDelete(ref canRemove, segLine2D, removeList);
            }
            // the currently operated is a V segment
            else if (-1 != m_drawing.SelectedVIndex)
            {
                GridLine2D    gridLine2D = m_drawing.VGridLines2D[m_drawing.SelectedVIndex];
                SegmentLine2D segLine2D  = gridLine2D.Segments[m_drawing.SelectedVSegmentIndex];

                int existingNumber = gridLine2D.Segments.Count - gridLine2D.RemovedNumber;
                // the to-be-deleted segment is the last one of the grid line, it's not allowed to delete it
                if (1 == existingNumber)
                {
                    canRemove = false;
                    return;
                }

                // simulative deletion
                gridLine2D.RemovedNumber++;
                segLine2D.Removed = true;
                gridLine2D.Segments[m_drawing.SelectedVSegmentIndex] = segLine2D;
                removeList.Add(segLine2D);
                // the "regeneration" step: if there're only 2 segments existing in one joint and they're in the same line, delete one seg will cause the other
                // been deleted automatically
                MimicRecursiveDelete(ref canRemove, segLine2D, removeList);
            }
        }
コード例 #5
0
ファイル: GridLine2D.cs プロジェクト: AMEE/revit
 /// <summary>
 /// copy constructor
 /// </summary>
 /// <param name="segLine2D">
 /// the source segment line 2D
 /// </param>
 public SegmentLine2D(SegmentLine2D segLine2D)
     : base((Line2D)segLine2D)
 {
     m_removed = segLine2D.Removed;
      m_isolated = segLine2D.Isolated;
      m_segmentIndex = segLine2D.SegmentIndex;
      m_gridLineIndex = segLine2D.GridLineIndex;
 }
コード例 #6
0
        /// <summary>
        /// move the selected grid line to the location of the mouse cursor
        /// </summary>
        /// <param name="mousePosition">
        /// indicates the destination position of the grid line
        /// </param>
        /// <returns>
        /// return whether the grid line be moved successfully
        /// </returns>
        public bool MoveGridLine(System.Drawing.Point mousePosition)
        {
            // verify that the mouse location is valid: it's inside the curtain grid area
            // & it doesn't lap over another grid line (it's not allowed to move a grid line to lap over another one)
            if (false == m_drawing.MouseLocationValid)
            {
                return(false);
            }

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

            // move a U line along the V direction
            if (-1 != m_drawing.SelectedUIndex)
            {
                // convert the 2D data to 3D
                Autodesk.Revit.DB.XYZ xyz = new Autodesk.Revit.DB.XYZ(mousePosition.X, mousePosition.Y, 0);
                Vector4 vec = new Vector4(xyz);
                vec = m_drawing.Coordinates.RestoreMatrix.Transform(vec);
                double offset = vec.Z - m_lineToBeMoved.FullCurve.GetEndPoint(0).Z;
                xyz = new Autodesk.Revit.DB.XYZ(0, 0, offset);
                Transaction act = new Transaction(m_activeDocument, Guid.NewGuid().GetHashCode().ToString());
                act.Start();
                try
                {
                    ElementTransformUtils.MoveElement(m_activeDocument, m_lineToBeMoved.Id, xyz);
                }
                catch (System.Exception e)
                {
                    TaskDialog.Show("Exception", e.Message);
                    return(false);
                }
                act.Commit();

                // update the grid line 2d
                GridLine2D line = m_drawing.UGridLines2D[m_drawing.SelectedUIndex];
                line.StartPoint = new System.Drawing.Point(line.StartPoint.X, line.StartPoint.Y + m_moveOffset);
                line.EndPoint   = new System.Drawing.Point(line.EndPoint.X, line.EndPoint.Y + m_moveOffset);

                // update the mapped grid line graphics path
                GraphicsPath path = new GraphicsPath();
                path.AddLine(line.StartPoint, line.EndPoint);
                m_drawing.ULinePathList[m_drawing.SelectedUIndex] = path;

                // update the mapped segment line and its graphics path
                List <GraphicsPath>  pathList    = m_drawing.USegLinePathListList[m_drawing.SelectedUIndex];
                List <SegmentLine2D> segLineList = line.Segments;
                for (int i = 0; i < segLineList.Count; i++)
                {
                    // update the segment
                    SegmentLine2D segLine2D = segLineList[i];
                    segLine2D.StartPoint = new System.Drawing.Point(segLine2D.StartPoint.X, segLine2D.StartPoint.Y + m_moveOffset);
                    segLine2D.EndPoint   = new System.Drawing.Point(segLine2D.EndPoint.X, segLine2D.EndPoint.Y + m_moveOffset);

                    // update the segment's graphics path
                    GraphicsPath gpath = new GraphicsPath();
                    path.AddLine(segLine2D.StartPoint, segLine2D.EndPoint);
                    pathList[i] = gpath;
                }
            }
            // move a V line along the U direction
            else if (-1 != m_drawing.SelectedVIndex)
            {
                // convert the 2D data to 3D
                Autodesk.Revit.DB.XYZ xyz = new Autodesk.Revit.DB.XYZ(mousePosition.X, mousePosition.Y, 0);
                Vector4 vec = new Vector4(xyz);
                vec = m_drawing.Coordinates.RestoreMatrix.Transform(vec);
                double offset = vec.X - m_lineToBeMoved.FullCurve.GetEndPoint(0).X;
                xyz = new Autodesk.Revit.DB.XYZ(offset, 0, 0);

                Transaction act = new Transaction(m_activeDocument, Guid.NewGuid().GetHashCode().ToString());
                act.Start();
                try
                {
                    ElementTransformUtils.MoveElement(m_activeDocument, m_lineToBeMoved.Id, xyz);
                }
                catch (System.Exception e)
                {
                    TaskDialog.Show("Exception", e.Message);
                    return(false);
                }
                act.Commit();

                // update the grid line 2d
                GridLine2D line = m_drawing.VGridLines2D[m_drawing.SelectedVIndex];
                line.StartPoint = new System.Drawing.Point(line.StartPoint.X + m_moveOffset, line.StartPoint.Y);
                line.EndPoint   = new System.Drawing.Point(line.EndPoint.X + m_moveOffset, line.EndPoint.Y);

                // update the mapped grid line graphics path
                GraphicsPath path = new GraphicsPath();
                path.AddLine(line.StartPoint, line.EndPoint);
                m_drawing.VLinePathList[m_drawing.SelectedVIndex] = path;

                // update the mapped segment line and its graphics path
                List <GraphicsPath>  pathList    = m_drawing.VSegLinePathListList[m_drawing.SelectedVIndex];
                List <SegmentLine2D> segLineList = line.Segments;
                for (int i = 0; i < segLineList.Count; i++)
                {
                    // update the segment
                    SegmentLine2D segLine2D = segLineList[i];
                    segLine2D.StartPoint = new System.Drawing.Point(segLine2D.StartPoint.X + m_moveOffset, segLine2D.StartPoint.Y);
                    segLine2D.EndPoint   = new System.Drawing.Point(segLine2D.EndPoint.X + m_moveOffset, segLine2D.EndPoint.Y);

                    // update the segment's graphics path
                    GraphicsPath gpath = new GraphicsPath();
                    path.AddLine(segLine2D.StartPoint, segLine2D.EndPoint);
                    pathList[i] = gpath;
                }
            }
            // line moved, the segment information changed, so reload all the geometry data
            this.ReloadGeometryData();

            m_drawing.DrawObject.Clear();
            return(true);
        }
コード例 #7
0
        /// <summary>
        /// add a new segment to the specified location
        /// </summary>
        public void AddSegment()
        {
            // verify that the mouse is inside the curtain grid area
            List <KeyValuePair <Line2D, Pen> > lines2D = m_drawing.DrawObject.Lines2D;

            if (lines2D.Count < 1)
            {
                return;
            }

            // the selected segment location is on a U grid line
            if (-1 != m_drawing.SelectedUIndex)
            {
                CurtainGridLine line  = m_uGridLines[m_drawing.SelectedUIndex];
                Curve           curve = line.AllSegmentCurves.get_Item(m_drawing.SelectedUSegmentIndex);
                if (null != line && null != curve)
                {
                    try
                    {
                        Transaction act = new Transaction(m_activeDocument, Guid.NewGuid().GetHashCode().ToString());

                        act.Start();
                        line.AddSegment(curve);
                        act.Commit();
                    }
                    catch (System.Exception e)
                    {
                        TaskDialog.Show("Exception", e.Message);
                        return;
                    }
                }

                GridLine2D gridLine2D = m_drawing.UGridLines2D[m_drawing.SelectedUIndex];
                gridLine2D.RemovedNumber--;
                SegmentLine2D segLine2D = gridLine2D.Segments[m_drawing.SelectedUSegmentIndex];
                segLine2D.Removed = false;
                gridLine2D.Segments[m_drawing.SelectedUSegmentIndex] = segLine2D;
            }
            // the selected segment location is on a V grid line
            else if (-1 != m_drawing.SelectedVIndex)
            {
                CurtainGridLine line  = m_vGridLines[m_drawing.SelectedVIndex];
                Curve           curve = line.AllSegmentCurves.get_Item(m_drawing.SelectedVSegmentIndex);
                if (null != line && null != curve)
                {
                    try
                    {
                        Transaction act = new Transaction(m_activeDocument, Guid.NewGuid().GetHashCode().ToString());
                        act.Start();
                        line.AddSegment(curve);
                        act.Commit();
                    }
                    catch (System.Exception e)
                    {
                        TaskDialog.Show("Exception", e.Message);
                        return;
                    }
                }

                GridLine2D gridLine2D = m_drawing.VGridLines2D[m_drawing.SelectedVIndex];
                gridLine2D.RemovedNumber--;
                SegmentLine2D segLine2D = gridLine2D.Segments[m_drawing.SelectedVSegmentIndex];
                segLine2D.Removed = false;
                gridLine2D.Segments[m_drawing.SelectedVSegmentIndex] = segLine2D;
            }

            this.ReloadGeometryData();
            m_drawing.DrawObject.Clear();
        }
コード例 #8
0
        /// <summary>
        /// remove the selected segment from the curtain grid
        /// </summary>
        public void RemoveSegment()
        {
            // verify that the mouse is inside the curtain grid area
            List <KeyValuePair <Line2D, Pen> > lines2D = m_drawing.DrawObject.Lines2D;

            if (lines2D.Count < 1)
            {
                return;
            }

            List <SegmentLine2D> toBeRemovedList = new List <SegmentLine2D>();
            // check whether the deletion is valid
            bool canRemove = true;

            MimicRemoveSegments(ref canRemove, toBeRemovedList);
            // in the "MimicRemove" process, we didn't find that we need to "Remove the last segment of the grid line"
            // so the "Remove" action can go on
            if (true == canRemove)
            {
                try
                {
                    Transaction act = new Transaction(m_activeDocument, Guid.NewGuid().GetHashCode().ToString());
                    act.Start();
                    foreach (SegmentLine2D seg2D in toBeRemovedList)
                    {
                        int  gridLineIndex = seg2D.GridLineIndex;
                        int  segIndex      = seg2D.SegmentIndex;
                        bool isUSegment    = seg2D.IsUSegment;

                        CurtainGridLine line;
                        if (true == isUSegment)
                        {
                            line = m_uGridLines[gridLineIndex];
                        }
                        else
                        {
                            line = m_vGridLines[gridLineIndex];
                        }
                        Curve curve = line.AllSegmentCurves.get_Item(segIndex);
                        line.RemoveSegment(curve);
                    }
                    act.Commit();
                }
                catch (System.Exception e)
                {
                    TaskDialog.Show("Exception", e.Message);
                    return;
                }
            }
            // in the "MimicRemove" process, we found that we would "Remove the last segment of the grid line"
            // so the whole "Remove" action will roll back
            else
            {
                foreach (SegmentLine2D seg2D in toBeRemovedList)
                {
                    int        gridLineIndex = seg2D.GridLineIndex;
                    int        segIndex      = seg2D.SegmentIndex;
                    bool       isUSegment    = seg2D.IsUSegment;
                    GridLine2D gridLine2D;

                    if (true == isUSegment)
                    {
                        gridLine2D = m_drawing.UGridLines2D[gridLineIndex];
                    }
                    else
                    {
                        gridLine2D = m_drawing.VGridLines2D[gridLineIndex];
                    }

                    gridLine2D.RemovedNumber--;
                    SegmentLine2D segLine2D = gridLine2D.Segments[segIndex];
                    segLine2D.Removed             = false;
                    gridLine2D.Segments[segIndex] = segLine2D;
                }
                string statusMsg = "Delete this segment will make some grid lines have no existent segments.";
                m_myDocument.Message = new KeyValuePair <string, bool>(statusMsg, true);
            }

            this.ReloadGeometryData();
            m_drawing.DrawObject.Clear();
        }
コード例 #9
0
ファイル: GridGeometry.cs プロジェクト: AMEE/revit
        /// <summary>
        /// the "regeneration" step: if there're only 2 segments existing in one joint and they're in the same line,
        /// delete one seg will cause the other been deleted automatically
        /// </summary>
        /// <param name="segLine2D">
        /// the to-be-automatically-deleted segment
        /// </param>
        /// <param name="removeList">
        /// the referred to-be-deleted list of the segments
        /// </param>
        /// <returns>
        /// returns the operation result: if there's no "last" segment in the deletion operation, return true; otherwise false
        /// </returns>
        private void MimicRecursiveDelete(ref bool canRemove, SegmentLine2D segLine2D, List<SegmentLine2D> removeList)
        {
            // the "regeneration" step: if there're only 2 segments existing in one joint
             // and they're in the same line, delete one seg will cause the other
             // been deleted automatically
             // get conjoint U line segments
             List<SegmentLine2D> removeSegments = new List<SegmentLine2D>();
             m_drawing.GetConjointSegments(segLine2D, removeSegments);

             // there's no isolated segment need to be removed automatically
             if (null == removeSegments || 0 == removeSegments.Count)
             {
            // didn't "remove last segment of the curtain grid line", all the operations are valid. so return true
            return;
             }

             // there're conjoint segments need to be removed automatically
             // add the segments to removeList first, and compute whether other segments need to be
             // removed automatically because of the deletion of this newly removed segment
             if (true == segLine2D.Removed)
             {
            foreach (SegmentLine2D seg in removeSegments)
            {
               MimicRemoveSegment(ref canRemove, seg, removeList);

               if (false == canRemove)
               {
                  return;
               }
               // recursive calling
               MimicRecursiveDelete(ref canRemove, seg, removeList);
            }
             }
        }
コード例 #10
0
ファイル: GridGeometry.cs プロジェクト: AMEE/revit
        /// <summary>
        /// remove the segment from the grid line
        /// </summary>
        /// <param name="canRemove">
        /// the returned result value, indicates whether the segment can be removed (is NOT the last segment)
        /// </param>
        /// <param name="seg">
        /// the to-be-removed segment
        /// </param>
        /// <param name="removeList">
        /// the referred to-be-deleted list of the segments
        /// </param>
        private void MimicRemoveSegment(ref bool canRemove, SegmentLine2D seg, List<SegmentLine2D> removeList)
        {
            int gridLineIndex = seg.GridLineIndex;
             int segIndex = seg.SegmentIndex;

             if (-1 != gridLineIndex && -1 != segIndex)
             {
            // update the gridline2d and segmentline2d data
            GridLine2D grid;
            if (true == seg.IsUSegment)
            {
               grid = m_drawing.UGridLines2D[gridLineIndex];
            }
            else
            {
               grid = m_drawing.VGridLines2D[gridLineIndex];
            }

            // the last segment of the grid line
            int existingNumber = grid.Segments.Count - grid.RemovedNumber;
            if (1 == existingNumber)
            {
               canRemove = false;
               return;
            }

            grid.RemovedNumber++;
            SegmentLine2D seg2D = grid.Segments[segIndex];
            seg2D.Removed = true;
            grid.Segments[segIndex] = seg2D;

            removeList.Add(seg2D);
             }
        }
コード例 #11
0
ファイル: GridDrawing.cs プロジェクト: AMEE/revit
        /// <summary>
        /// check whether the segments which have the same junction with the specified segment 
        /// will be isolated if we delete the specified segment
        /// for example: 2 grid line has one junction, so there'll be 4 segments connecting to this junction
        /// let's delete 2 segments out of the 4 first, then if we want to delete the 3rd segment, the 4th 
        /// segment will be a "isolated" one, so we will pick this kind of segment out
        /// </summary>
        /// <param name="segLine">
        /// the specified segment used to checking
        /// </param>
        /// <param name="removeSegments">
        /// the result seg list (all the segments in this list is to-be-deleted)
        /// </param>
        public void GetConjointSegments(SegmentLine2D segLine,
          List<SegmentLine2D> removeSegments)
        {
            System.Drawing.Point startPoint = segLine.StartPoint;
             System.Drawing.Point endPoint = segLine.EndPoint;

             // get the "isolated" segment in the location of start point
             SegmentLine2D startRemoveSegLine = new SegmentLine2D();
             GetConjointSegment(startPoint, segLine.IsUSegment, ref startRemoveSegLine);
             // get the "isolated" segment in the location of end point
             SegmentLine2D endRemoveSegLine = new SegmentLine2D();
             GetConjointSegment(endPoint, segLine.IsUSegment, ref endRemoveSegLine);

             if (null != startRemoveSegLine)
             {
            removeSegments.Add(startRemoveSegLine);
             }
             if (null != endRemoveSegLine)
             {
            removeSegments.Add(endRemoveSegLine);
             }
        }
コード例 #12
0
ファイル: GridDrawing.cs プロジェクト: AMEE/revit
        /// <summary>
        /// identify whether the segment is contained in the segments of a grid line
        /// </summary>
        /// <param name="lines">
        /// the grid line (may contain the specified segment)
        /// </param>
        /// <param name="lineB">
        /// the segment which needs to be identified
        /// </param>
        /// <returns>
        /// if the segment is contained in the grid line, return true; otherwise false
        /// </returns>
        private bool IsSegLineContained(List<SegmentLine2D> lines, SegmentLine2D lineB)
        {
            foreach (SegmentLine2D lineA in lines)
             {
            System.Drawing.Point lineAStartPoint = lineA.StartPoint;
            System.Drawing.Point lineAEndPoint = lineA.EndPoint;
            System.Drawing.Point lineBStartPoint = lineB.StartPoint;
            System.Drawing.Point lineBEndPoint = lineB.EndPoint;

            // the 2 lines have the same start point and the same end point
            if ((true == IsPointsEqual(lineAStartPoint, lineBStartPoint) && true == IsPointsEqual(lineAEndPoint, lineBEndPoint)) ||
                (true == IsPointsEqual(lineAStartPoint, lineBEndPoint) && true == IsPointsEqual(lineAEndPoint, lineBStartPoint)))
            {
               return true;
            }
             }

             return false;
        }
コード例 #13
0
ファイル: GridDrawing.cs プロジェクト: AMEE/revit
        /// <summary>
        /// get all the segments of the specified grid line
        /// </summary>
        /// <param name="gridLine2D">
        /// the grid line which wants to get all its segments
        /// </param>
        /// <param name="allCurves">
        /// all the segments (include existent ones and skipped one)
        /// </param>
        /// <param name="skippedSegments">
        /// the skipped segments
        /// </param>
        /// <param name="segPaths">
        /// the GraphicsPath list contains all the segments
        /// </param>
        /// <param name="gridLineIndex">
        /// the index of the grid line
        /// </param>
        private void GetSegments(GridLine2D gridLine2D, CurveArray allCurves,
          List<SegmentLine2D> skippedSegments, List<GraphicsPath> segPaths,
          int gridLineIndex)
        {
            int segIndex = -1;
             // convert the segments from Curve format to SegmentLine2D format (from 3D to 2D)
             foreach (Curve curve in allCurves)
             {
            // store the index of the segment in the grid line
            segIndex++;
            Autodesk.Revit.DB.XYZ point1 = curve.get_EndPoint(0);
            Autodesk.Revit.DB.XYZ point2 = curve.get_EndPoint(1);

            Vector4 v1 = new Vector4(point1);
            Vector4 v2 = new Vector4(point2);

            // transform from 3D point to 2D point
            v1 = m_coordinates.TransformMatrix.Transform(v1);
            v2 = m_coordinates.TransformMatrix.Transform(v2);

            // add the segment data
            SegmentLine2D segLine2D = new SegmentLine2D();
            segLine2D.StartPoint = new System.Drawing.Point((int)v1.X, (int)v1.Y);
            segLine2D.EndPoint = new System.Drawing.Point((int)v2.X, (int)v2.Y);
            // if the segment is contained in the skipped list, set the Removed flag to true; otherwise false
            segLine2D.Removed = IsSegLineContained(skippedSegments, segLine2D);
            // if the segment is in a U grid line, set it true; otherwise false
            segLine2D.IsUSegment = gridLine2D.IsUGridLine;
            // the index of the parent grid line in the grid line list
            segLine2D.GridLineIndex = gridLineIndex;
            // the index of the segment in its parent grid line
            segLine2D.SegmentIndex = segIndex;
            if (true == segLine2D.Removed)
            {
               gridLine2D.RemovedNumber++;
            }
            gridLine2D.Segments.Add(segLine2D);

            // store the mapped graphics path
            GraphicsPath path = new GraphicsPath();
            path.AddLine(segLine2D.StartPoint, segLine2D.EndPoint);
            segPaths.Add(path);
             }
        }
コード例 #14
0
ファイル: GridDrawing.cs プロジェクト: AMEE/revit
        /// <summary>
        /// get all the segments which is connected to the end point of the segment and is in the same line as the segment
        /// for example: 2 grid line has one junction, so there'll be 4 segments connecting to this junction
        /// 2 U segments and 2 V segments, delete the 2 U segments first, then delete one of the V segment, the other V segment
        /// will be marked as the "ConjointSegment" and will be deleted automatically.
        /// this method is used to pick the "the other V segment" out
        /// </summary>
        /// <param name="point">
        /// the junction of several segments
        /// </param>
        /// <param name="isUSegment">
        /// the U/V status of the segment
        /// </param>
        /// <param name="removeSegLine">
        /// the result segment line to be removed
        /// </param>
        private void GetConjointSegment(System.Drawing.Point point, bool isUSegment,
           ref SegmentLine2D removeSegLine)
        {
            int uIndex = -1;
             List<int> uSegIndexes = new List<int>();
             // get which U grid line contains the point
             uIndex = GetOutlineIndex(m_uLinePathList, point);

             int vIndex = -1;
             List<int> vSegIndexes = new List<int>();
             // get which V grid line contains the point
             vIndex = GetOutlineIndex(m_vLinePathList, point);

             if (-1 != uIndex)
             {
            // get the grid line containing the point and its segments
            List<SegmentLine2D> segList = m_uGridLines2D[uIndex].Segments;
            // get which segments of the grid line contains the point
            uSegIndexes = GetOutlineIndexes(segList, point);
             }

             if (-1 != vIndex)
             {
            // get the grid line containing the point and its segments
            List<SegmentLine2D> segList = m_vGridLines2D[vIndex].Segments;
            // get which segments of the grid line contains the point
            vSegIndexes = GetOutlineIndexes(segList, point);
             }

             if ((0 == uSegIndexes.Count && 1 == vSegIndexes.Count))
             {
            // the source segment is an V segment, and the result segment is a V segment too.
            // they're connected and in one line, so the result V segment should be removed,
            // according to the UI rule
            if (false == isUSegment)
            {
               removeSegLine = m_vGridLines2D[vIndex].Segments[vSegIndexes[0]];
               return;
            }
             }
             else if (1 == uSegIndexes.Count && 0 == vSegIndexes.Count)
             {
            // the source segment is an U segment, and the result segment is a U segment too.
            // they're connected and in one line, so the result U segment should be removed,
            // according to the UI rule
            if (true == isUSegment)
            {
               removeSegLine = m_uGridLines2D[uIndex].Segments[uSegIndexes[0]];
               return;
            }
             }
        }
コード例 #15
0
ファイル: GridDrawing.cs プロジェクト: AMEE/revit
        /// <summary>
        /// convert the segment lines in Curve format to SegmentLine2D format
        /// </summary>
        /// <param name="curveArray">
        /// the skipped segments in Curve (used in RevitAPI) format 
        /// </param>
        /// <returns>
        /// the skipped segments in SegmentLine2D format (converted from 3D to 2D)
        /// </returns>
        private List<SegmentLine2D> ConvertCurveToSegment(CurveArray curveArray)
        {
            List<SegmentLine2D> resultList = new List<SegmentLine2D>();

             // convert the skipped segments (in Curve format) to SegmentLine2D format
             foreach (Curve curve in curveArray)
             {
            Autodesk.Revit.DB.XYZ point1 = curve.get_EndPoint(0);
            Autodesk.Revit.DB.XYZ point2 = curve.get_EndPoint(1);

            Vector4 v1 = new Vector4(point1);
            Vector4 v2 = new Vector4(point2);

            // transform from 3D point to 2D point
            v1 = m_coordinates.TransformMatrix.Transform(v1);
            v2 = m_coordinates.TransformMatrix.Transform(v2);

            // add the segment data
            SegmentLine2D segLine2D = new SegmentLine2D();
            segLine2D.StartPoint = new System.Drawing.Point((int)v1.X, (int)v1.Y);
            segLine2D.EndPoint = new System.Drawing.Point((int)v2.X, (int)v2.Y);
            resultList.Add(segLine2D);
             }

             return resultList;
        }