예제 #1
0
        public override void MouseUpHandler(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left)
            {
                if (_isStarted && !_isEnded && !_isDragging)  // First click
                {
                    _isDragging      = true;
                    _mouseDownOrigin = MapControl.Current.GetWorldCoord(e.GetPosition(MapControl.Current));
                    _mouseDownBegin  = _mouseDownOrigin;
                    _clickPoints.Add(_mouseDownBegin);
                }
                else if (_isEnded)  // Last click
                {
                    //_clickPoints.Remove(_mouseDownOrigin);
                    this.Render();

                    if (_clickPoints.Count > 1)
                    {
                        var areaPoly = new PointString(_clickPoints);
                        _areaLabel.Text = "Area: " + areaPoly.Area().ToString("0.000") + "m²";
                        Canvas.SetLeft(_areaLabel, MapControl.Current.GetCanvasCoord(_clickPoints.ElementAt(_clickPoints.Count - 1)).X + 10);
                        Canvas.SetTop(_areaLabel, MapControl.Current.GetCanvasCoord(_clickPoints.ElementAt(_clickPoints.Count - 1)).Y + 15);
                    }
                }
                else // Middle clicks
                {
                    _mouseDownOrigin = MapControl.Current.GetWorldCoord((e.GetPosition(MapControl.Current)));
                    _clickPoints.Add(_mouseDownOrigin);
                    this.Render();
                }
            }
        }
예제 #2
0
        public Point GetCanvasCoord(Geometry.Vector worldCoord)
        {
            double x = worldCoord.X / Scale + Origin.X;
            double y = Origin.Y - worldCoord.Y / Scale;

            return(new Point(x, y));
        }
예제 #3
0
        public LoadCase LoadPatternToSpeckle(string loadPatternName)
        {
            var speckleLoadCase = new LoadCase();

            speckleLoadCase.loadType = GetAndConvertEtabsLoadType(loadPatternName);
            speckleLoadCase.name     = loadPatternName;
            var selfweight = GetSelfWeightMultiplier(loadPatternName);

            //Encoding loadPatterns selfweight multiplier within
            if (selfweight != 0)
            {
                var gravityVector = new Geometry.Vector(0, 0, -selfweight);
                var gravityLoad   = new LoadGravity(speckleLoadCase, gravityVector);
                gravityLoad.name = loadPatternName;
                SpeckleModel.loads.Add(gravityLoad);
            }
            else
            {
                var gravityVector = new Geometry.Vector(0, 0, 0);
                var gravityLoad   = new LoadGravity(speckleLoadCase, gravityVector);
                gravityLoad.name = loadPatternName;
                SpeckleModel.loads.Add(gravityLoad);
            }
            if (SpeckleModel.loads.Contains(speckleLoadCase))
            {
            }
            else
            {
                SpeckleModel.loads.Add(speckleLoadCase);
            }


            return(speckleLoadCase);
        }
예제 #4
0
        private void DelaunayRefine(int scenario)
        {
            var sw = new Stopwatch();

            sw.Start();
            Random      rng = new Random();
            BoundingBox box = new BoundingBox(0, 10, -10, 0, 0, 0);

            int size = 50;

            Geometry.Vector[] points;
            if (scenario == 1)
            {
                points = box.RandomPointsInside(rng, size);
            }
            else if (scenario == 2)
            {
                points = new Geometry.Vector[]
                {
                    new Geometry.Vector(10, -9.5),
                    new Geometry.Vector(0, -9.5),
                    new Geometry.Vector(2, -0.5),
                    new Geometry.Vector(8, -0.5)
                    //new Geometry.Vector(4.5,-0.5),
                    //new Geometry.Vector(5.5,-0.5)
                };
            }
            else
            {
                points = new Geometry.Vector[]
                {
                    new Geometry.Vector(10, -6),
                    new Geometry.Vector(10, -2),
                    new Geometry.Vector(0, -6),
                    //new Geometry.Vector(0, -6)
                };
            }
            VertexCollection   verts = new VertexCollection(points);
            MeshFaceCollection faces = Mesh.DelaunayTriangulationXY(verts);

            faces.Quadrangulate();
            faces = faces.Refine(0.5);
            //Dictionary<Vertex, MeshFace> voronoi = Mesh.VoronoiFromDelaunay(verts, faces);
            //ShapeCollection geometry = new MeshFaceCollection(voronoi.Values).ExtractFaceBoundaries();
            CurveCollection          edges    = faces.ExtractFaceBoundaries();
            VertexGeometryCollection geometry = new VertexGeometryCollection();

            foreach (var edge in edges)
            {
                var region = new PlanarRegion(edge);
                geometry.Add(region);
                region.Attributes = new GeometryAttributes(new Colour(128, 0, 255, 128));
                geometry.Add(edge);
                edge.Attributes = new GeometryAttributes(new Colour(64, 0, 0, 0));
            }
            geometry.Add(new Cloud(verts.ExtractPoints()));
            sw.Stop();
            MeshingTimeText.Text    = "Completed: " + faces.Count + " faces in " + sw.Elapsed;
            DelaunayCanvas.Geometry = geometry;
        }
예제 #5
0
        public override void MouseUpHandler(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left)
            {
                if (!_isEnded && _isStarted && !_isDragging)
                {
                    _isDragging      = true;
                    _mouseDownOrigin = MapControl.Current.GetWorldCoord(e.GetPosition(MapControl.Current));
                    _clickPoints.Add(_mouseDownOrigin);
                }
                else if (_isEnded)
                {
                }
                else
                {
                    _tempMouseDownEnd = _mouseDownEnd;
                    _clickPoints.Add(_mouseDownEnd);

                    double distance  = Enumerable.Range(0, _clickPoints.Count - 1).Sum(i => _clickPoints[i].Dist(_clickPoints[i + 1]));
                    var    tempLabel = new TextBlock {
                        Text = distance.ToString("0.000") + "m"
                    };
                    Canvas.SetLeft(tempLabel, MapControl.Current.GetCanvasCoord(_mouseDownEnd).X + 10);
                    Canvas.SetTop(tempLabel, MapControl.Current.GetCanvasCoord(_mouseDownEnd).Y + 15);

                    _labels.Add(tempLabel, _mouseDownEnd);
                    MapControl.Current.Children.Add(tempLabel);
                }
            }
        }
예제 #6
0
 public override void MouseMoveHandler(object sender, MouseEventArgs e)
 {
     if (!_isEnded && _isDragging)
     {
         _mouseDownEnd = MapControl.Current.GetWorldCoord(e.GetPosition(MapControl.Current));
     }
     this.Render();
 }
예제 #7
0
        public void LocateCanvas(Geometry.Vector location)
        {
            double radius  = 500;
            var    pt1     = new Geometry.Vector(location.X + radius, location.Y + radius);
            var    pt2     = new Geometry.Vector(location.X - radius, location.Y - radius);
            var    extents = Extents.FromPoints(pt2, pt1);

            this.Zoom(extents);
        }
예제 #8
0
 public override void MouseMoveHandler(object sender, MouseEventArgs e)
 {
     if (_isDragging)
     {
         this.Rect.Visibility = Visibility.Visible;
         _mouseDownEnd        = MapControl.Current.GetWorldCoord(e.GetPosition(MapControl.Current));
         this.Render();
     }
 }
예제 #9
0
 public static void markcell(Geometry.Vector p)
 {
     System.Windows.Shapes.Ellipse ell = new System.Windows.Shapes.Ellipse {
         Width = spotsize, Height = spotsize, Fill = new SolidColorBrush(spotcolor)
     };
     System.Windows.Controls.Canvas.SetLeft(ell, p.X - spotsize / 2);
     System.Windows.Controls.Canvas.SetTop(ell, p.Y - spotsize / 2);
     MapControl.Current.MarkLayer.Children.Add(ell);
 }
        /// <summary>
        /// .Moves a single entity by a specified relative amount.
        /// </summary>
        /// <param name="entityToMove">The single entity that is to be moved.</param>
        /// <param name="moveVector">The relative amount by which the entity will be moved.</param>
        /// <param name="copiesToCreate">The number of copies that should be created by the operation.</param>
        public static List <PSEntity> MoveEntityByVector(IPSMoveable entityToMove, Geometry.Vector moveVector, int copiesToCreate)
        {
            // Create a list of the single entity
            List <IPSMoveable> entityToMoveList = new List <IPSMoveable>();

            entityToMoveList.Add(entityToMove);

            // Carry out move operation
            return(MoveEntitiesByVector(entityToMoveList, moveVector, copiesToCreate));
        }
예제 #11
0
        public static IFeature addspot(Geometry.Vector pos)
        {
            Feature f = new Feature(pos);

            f["ga-type"]   = "default";
            f["ga-radius"] = "500";
            f["ga-mass"]   = "1000";
            _spotLayer.AddFeature(f);
            return(f);
        }
예제 #12
0
        private static IFeature getcellfeature(Geometry.Vector cell)
        {
            var     p1    = cell.Add(new Geometry.Vector(cellsize / 2, cellsize / 2));
            var     p2    = cell.Add(new Geometry.Vector(cellsize / 2, -cellsize / 2));
            var     p3    = cell.Add(new Geometry.Vector(-cellsize / 2, -cellsize / 2));
            var     p4    = cell.Add(new Geometry.Vector(-cellsize / 2, cellsize / 2));
            Feature f     = new Feature(p1, p2, p3, p4);
            double  value = function(cell);

            f.Properties["value"] = value.ToString();
            valuecache[cell]      = value;
            return(f);
        }
예제 #13
0
        /// <summary>
        /// This operation creates a new Workplane from just an origin and a Z axis.  The X and Y axes are
        /// created off the Z axis orientation.
        /// </summary>
        /// <param name="origin">The origin at which to create the new workplane.</param>
        /// <param name="zAxis">The Z axis of the new workplane.</param>
        /// <returns>The created workplane.</returns>
        public PSWorkplane CreateWorkplaneFromZAxis(Geometry.Point origin, Geometry.Vector zAxis)
        {
            // Ensure that the z axis is normalised so as not to skew the X and Y axes when they get created
            Geometry.Vector localZAxis = zAxis.Clone();
            localZAxis.Normalize();

            Geometry.Vector xAxis = null;
            Geometry.Vector yAxis = null;
            localZAxis.GetXYVectors(ref xAxis, ref yAxis);

            PSWorkplane newWorkplane = new PSWorkplane(_powerSHAPE, new Geometry.Workplane(origin, xAxis, yAxis, localZAxis));

            Add(newWorkplane);
            return(newWorkplane);
        }
예제 #14
0
        /// <summary>
        /// This operation creates a new Workplane from just an origin and an X and Y axis.  The Z axis is
        /// created off the X and Y axes orientation.
        /// </summary>
        /// <param name="origin">The origin at which to create the new workplane.</param>
        /// <param name="xAxis">The X axis of the new workplane.</param>
        /// <param name="yAxis">The Y axis of the new workplane.</param>
        /// <returns>The created workplane.</returns>
        public PSWorkplane CreateWorkplaneFromXYAxes(Geometry.Point origin, Geometry.Vector xAxis, Geometry.Vector yAxis)
        {
            // Ensure that the x and y axes are normalised so as not to skew the Z axis when it gets created
            Geometry.Vector localXAxis = xAxis.Clone();
            localXAxis.Normalize();
            Geometry.Vector localYAxis = yAxis.Clone();
            localYAxis.Normalize();

            Geometry.Vector zAxis = Geometry.Vector.CrossProduct(localXAxis, localYAxis);

            PSWorkplane newWorkplane =
                new PSWorkplane(_powerSHAPE, new Geometry.Workplane(origin, localXAxis, localYAxis, zAxis));

            Add(newWorkplane);
            return(newWorkplane);
        }
예제 #15
0
 public override void MouseDownHandler(object sender, MouseButtonEventArgs e)
 {
     if (e.ChangedButton == MouseButton.Left)
     {
         if (!_isStarted)
         {
             _isStarted  = true;
             _isDragging = true;
             Point pos = e.GetPosition(MapControl.Current);
             _mouseDownOrigin = MapControl.Current.GetWorldCoord(pos);
         }
         else
         {
             _isStarted = false;
         }
     }
 }
예제 #16
0
        public override void MouseDownHandler(object sender, MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left)
            {
                if (_isDragging == false)
                {
                    _isDragging      = true;
                    _mouseDownOrigin = MapControl.Current.GetWorldCoord(e.GetPosition(MapControl.Current));
                    return;
                }

                _mouseDownEnd = MapControl.Current.GetWorldCoord(e.GetPosition(MapControl.Current));
                var extents     = Extents.FromPoints(_mouseDownOrigin, _mouseDownEnd);
                var queryResult = MapDataManager.LatestMap
                                  .QueryFeatures(IsWindow ? SpatialQueryOperation.Window : SpatialQueryOperation.Cross, extents, 0)
                                  .ToArray();

                if (queryResult.Length > 0)
                {
                    if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift &&
                        (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)    // mod 20140725
                    {
                        SelectionSet.SubtractSelection(queryResult);
                    }
                    else if ((Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift) // mod 20120810
                    {
                        SelectionSet.AddSelection(queryResult);
                    }
                    else
                    {
                        SelectionSet.Select(queryResult); // mod 20120725
                    }
                }
                else
                {
                    SelectionSet.ClearSelection();
                }

                _isDragging          = false;
                this.Rect.Visibility = Visibility.Collapsed;
            }
        }
예제 #17
0
        public static MeshGeometry3D Road(PointString poly, double width)
        {
            var grid = new Geometry.Vector[(poly.Points.Count - 1) * 2, 3];

            for (var i = 0; i < poly.Points.Count - 1; i++)
            {
                var a    = poly.Points[i];
                var b    = poly.Points[i + 1];
                var dir  = b - a;
                var norm = dir.Cross(Geometry.Vector.ZAxis).Normalize();
                var j    = 2 * i;
                grid[j, 0]     = a.Add(-0.5 * width * norm);
                grid[j, 1]     = a;
                grid[j, 2]     = a.Add(0.5 * width * norm);
                grid[j + 1, 0] = b.Add(-0.5 * width * norm);
                grid[j + 1, 1] = b;
                grid[j + 1, 2] = b.Add(0.5 * width * norm);
            }
            return(Geometry3D.MeshBuilder.RectGrid(grid).ToMesh().ToWpfMesh());
        }
예제 #18
0
        private void AnalysisMeshButton_Click(object sender, RoutedEventArgs e)
        {
            Random      rng = new Random();
            BoundingBox box = new BoundingBox(1, 9, -9, -1, 0, 0);

            int size = 100;
            //Geometry.Vector[] points = box.RandomPointsInside(rng, size);
            //VertexCollection verts = new VertexCollection(points);

            VertexCollection verts = new VertexCollection();
            //verts.Add(new Vertex(1, -1));
            int divs = 5;

            for (int i = 0; i <= divs; i++)
            {
                for (int j = 0; j <= divs; j++)
                {
                    Geometry.Vector pt = new Geometry.Vector(box.X.ValueAt(((double)i) / divs), box.Y.ValueAt(((double)j) / divs));
                    verts.Add(new Vertex(pt));
                }
            }

            MeshFaceCollection faces = Mesh.DelaunayTriangulationXY(verts);

            faces.Quadrangulate();
            //Dictionary<Vertex, MeshFace> voronoi = Mesh.VoronoiFromDelaunay(verts, faces);
            //ShapeCollection geometry = new MeshFaceCollection(voronoi.Values).ExtractFaceBoundaries();
            CurveCollection          edges    = faces.ExtractFaceBoundaries();
            VertexGeometryCollection geometry = new VertexGeometryCollection();

            foreach (var edge in edges)
            {
                var region = new PlanarRegion(edge);
                geometry.Add(region);
                region.Attributes = new GeometryAttributes(new Colour(128, 0, 255, 128));
                geometry.Add(edge);
                edge.Attributes = new GeometryAttributes(new Colour(64, 0, 0, 0));
            }
            geometry.Add(new Cloud(verts.ExtractPoints()));
            DelaunayCanvas.Geometry = geometry;
        }
        /// <summary>
        /// Moves a group of entities by a specified relative amount.
        /// </summary>
        /// <param name="entitiesToMove">The group of entities that are to be moved.</param>
        /// <param name="moveVector">The relative amount by which each entity will be moved.</param>
        /// <param name="copiesToCreate">The number of copies that should be created by the operation.</param>
        /// <returns>A list containing any created copies of the original entities.  If copiesToCreate is 0, the operation returns an empty list.</returns>
        public static List <PSEntity> MoveEntitiesByVector(
            List <IPSMoveable> entitiesToMove,
            Geometry.Vector moveVector,
            int copiesToCreate)
        {
            SetupMove(entitiesToMove, copiesToCreate);

            // Carry out the process
            if (_powerSHAPE.Version >= new Version("11.2"))
            {
                _powerSHAPE.DoCommand("X " + moveVector.I.ToString(),
                                      "Y " + moveVector.J.ToString(),
                                      "Z " + moveVector.K.ToString());
                _powerSHAPE.DoCommand("APPLY", "DISMISS");
            }
            else
            {
                _powerSHAPE.DoCommand(moveVector.I.ToString() + " " + moveVector.J.ToString() + " " + moveVector.K.ToString());
                _powerSHAPE.DoCommand("CANCEL");
            }

            return(FinishMove());
        }
예제 #20
0
 private Point VectorToPoint(Geometry.Vector v)
 {
     return(new Point(v.X * Magnification, ActualHeight - v.Y * Magnification));
 }
예제 #21
0
 protected void OnPointPicked(Geometry.Vector p)
 {
     this.PointPicked?.Invoke(p);
 }
예제 #22
0
 /// <summary>
 /// Moves a single curve by a specified relative amount
 /// </summary>
 /// <param name="moveVector">Relative amount by which the curve will be moved</param>
 /// <param name="copiesToCreate">Number of copies that should be created by the operation</param>
 public List <PSEntity> MoveByVector(Geometry.Vector moveVector, int copiesToCreate)
 {
     return(PSEntityMover.MoveEntityByVector(this, moveVector, copiesToCreate));
 }