private static List <List <DataPoint> > SimplifyBoundary(PolygonBoundary boundary)
        {
            var points = boundary.Points;

            List <DataPoint> xyPoints = new List <DataPoint>();

            foreach (var point in points)
            {
                double ptX = 0;
                double ptY = 0;
                point.GetCoordinates(out ptX, out ptY);
                DataPoint dataPoint = new DataPoint(ptX, ptY);
                xyPoints.Add(dataPoint);
            }

            // need to turn these into a set of triangles
            List <List <DataPoint> > simpleAreaSet =
                PolygonSimplifier.TriangulatePolygon(xyPoints);

            return(simpleAreaSet);
        }
        public static List <List <Point3D> > SimplifyBoundary(PolygonBoundary boundary)
        {
            List <PolygonPoint> points = boundary.Points;

            List <Point3D> xyPoints = new List <Point3D>();

            foreach (PolygonPoint point in points)
            {
                double ptX;
                double ptY;
                point.GetCoordinates(out ptX, out ptY);
                Point3D dataPoint = new Point3D(ptX, ptY, 0);
                xyPoints.Add(dataPoint);
            }

            // need to turn these into a set of triangles
            List <List <Point3D> > simpleAreaSet =
                PolygonSimplifier.TriangulatePolygon(xyPoints);

            return(simpleAreaSet);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Defines the query.
        /// </summary>
        /// <param name="queryModel">The query model.</param>
        /// <returns></returns>
        private bool DefineQuery(QueryModel queryModel)
        {
            //_logger.Info("Defining AutoCAD Map Query...");

            bool retVal = false;

            //_logger.Debug("Start DefineQuery");
            try
            {
                // create query branch
                //
                QueryBranch queryBranch = QueryBranch.Create();

                // create query conditions
                //
                IList <QueryCondition> queryConditions = new List <QueryCondition>();

                // location filter
                //
                if (this.UseBoundry)
                {
                    //_logger.Info("Defining AutoCAD Map Location Query...");
                    // define the window based on the users selection points
                    //
                    LocationCondition qryCondition = new LocationCondition();
                    qryCondition.JoinOperator = JoinOperator.OperatorAnd;
                    qryCondition.LocationType = this.LocationType;
                    LocationBoundary boundary = new PolygonBoundary(this.SelectionPoints);
                    qryCondition.Boundary = boundary;
                    queryBranch.AppendOperand(qryCondition);
                    queryConditions.Add(qryCondition);
                }

                // object filter
                //
                if (this.ObjectFilters.Count == 0)
                {
                    //_logger.Info("Defining AutoCAD Map Property * Query...");
                    PropertyCondition propCondition = new PropertyCondition();
                    propCondition.JoinOperator = JoinOperator.OperatorAnd;
                    propCondition.PropertyType = PropertyType.EntityType;
                    propCondition.Value        = "*";
                    queryBranch.AppendOperand(propCondition);
                    queryConditions.Add(propCondition);
                }
                else
                {
                    bool isFirstObjectType = true;
                    int  firstIndex        = 0;
                    int  lastIndex         = 0;

                    firstIndex = queryBranch.OperandCount;
                    //_logger.Info("Defining AutoCAD Map Property Query...");
                    foreach (string objectFilter in this.ObjectFilters)
                    {
                        PropertyCondition propCondition = new PropertyCondition();
                        if (isFirstObjectType == true)
                        {
                            propCondition.JoinOperator = JoinOperator.OperatorAnd;
                            isFirstObjectType          = false;
                        }
                        else
                        {
                            propCondition.JoinOperator = JoinOperator.OperatorOr;
                        }
                        propCondition.PropertyType = PropertyType.EntityType;
                        propCondition.Value        = objectFilter;
                        queryBranch.AppendOperand(propCondition);
                        queryConditions.Add(propCondition);
                    }

                    //TODO: Why does queryBranch.Group not work?
                    if (this.ObjectFilters.Count > 1)
                    {
                        lastIndex  = queryBranch.OperandCount - firstIndex;
                        lastIndex -= 1;
                        queryBranch.Group(firstIndex, lastIndex);
                    }
                }

                // block name filter
                //
                if (this.BlockNameFilters.Count > 0)
                {
                    bool isFirstBlockName = true;
                    int  firstIndex       = 0;
                    int  lastIndex        = 0;

                    firstIndex = queryBranch.OperandCount;
                    //_logger.Info("Defining AutoCAD Map Block Name Query...");
                    foreach (string blockNameFilter in this.BlockNameFilters)
                    {
                        PropertyCondition propCondition = new PropertyCondition();
                        if (isFirstBlockName == true)
                        {
                            propCondition.JoinOperator = JoinOperator.OperatorAnd;
                            isFirstBlockName           = false;
                        }
                        else
                        {
                            propCondition.JoinOperator = JoinOperator.OperatorOr;
                        }
                        propCondition.PropertyType = PropertyType.BlockName;
                        propCondition.Value        = blockNameFilter;
                        queryBranch.AppendOperand(propCondition);
                        queryConditions.Add(propCondition);
                    }

                    //TODO: Why does queryBranch.Group not work?
                    if (this.BlockNameFilters.Count > 1)
                    {
                        lastIndex  = queryBranch.OperandCount - firstIndex;
                        lastIndex -= 1;
                        queryBranch.Group(firstIndex, lastIndex);
                    }
                }

                // layer filter
                //
                foreach (string layerFilter in this.LayerFilters)
                {
                    PropertyCondition layerPropertyCondition = new PropertyCondition();
                    layerPropertyCondition.JoinOperator = JoinOperator.OperatorAnd;
                    layerPropertyCondition.PropertyType = PropertyType.Layer;
                    layerPropertyCondition.Value        = layerFilter;
                    queryBranch.AppendOperand(layerPropertyCondition);
                    queryConditions.Add(layerPropertyCondition);
                }

                // Define query
                //
                queryModel.Define(queryBranch);

                // clean up
                foreach (QueryCondition pc in queryConditions)
                {
                    pc.Dispose();
                }
                queryBranch.Dispose();

                retVal = true;
            }
            catch (System.Exception ex)
            {
                //_logger.Error("Error defining query", ex);
                throw;
                //AcadUtilities.WriteMessage("\nError defining query");
            }
            //_logger.Debug("End DefineQuery");
            return(retVal);
        }