コード例 #1
0
        /// <summary>
        /// Called when the position input is changed
        /// </summary>
        /// <param name="p">The new location point</param>
        /// <param name="didSnap">Information on point snapping</param>
        /// <returns>true, if point is accepted</returns>
        bool OnSetPosition(GeoPoint p, SnapPointFinder.DidSnapModes didSnap)
        {
            location = p;
            // default vectors for the two sides of the bitmap
            GeoVector dirWidth  = ActiveDrawingPlane.DirectionX;
            GeoVector dirHeight = ActiveDrawingPlane.DirectionY;

            if (didSnap == SnapPointFinder.DidSnapModes.DidSnapToFaceSurface)
            {                                                                 // if there was a snap on the surface of a face we want to center the picture object
                // there. We also want to make it parallel to the surface at this point and stand upright.
                Face fc = base.LastSnapObject as Face;                        // this object was involved in the snapping
                if (fc != null)                                               // should always be the case
                {
                    GeoPoint2D pos        = fc.Surface.PositionOf(location);  // position in the surface u/v system
                    GeoVector  normal     = fc.Surface.GetNormal(pos);        // normal vector at this position
                    Projection projection = base.CurrentMouseView.Projection; // the projection of the view
                    if (projection != null)
                    {                                                         // make sure that the normal vector points away from the user.
                        // On faces not in a solid both sides of the face are displayed and you don't know
                        // on which side you are
                        if (projection.Direction * normal < 0.0)
                        {
                            normal = -normal;
                        }
                    }
                    location = location - 0.001 * normal.Normalized; // moves the location point a little bit
                    // in the direction of the normal vector to the user so
                    // that the bitmap hovers a little above the surface to avoid display artefacts
                    if (Precision.SameDirection(normal, GeoVector.ZAxis, false))
                    {   // the surface is parallel to the x/y plane: orient the bitmap to the x/y axis
                        dirWidth  = GeoVector.XAxis;
                        dirHeight = GeoVector.YAxis;
                    }
                    else
                    {   // some arbitrary surface direction: calculate the base direction of the bitmap to
                        // be parallel to the x/y plane and the up direction rectangular to the base and the normal.
                        // this makes the bitmap appear upright (in the sense of the z-axis)
                        dirWidth  = normal ^ GeoVector.ZAxis;
                        dirHeight = dirWidth ^ normal;
                        dirWidth.Norm(); // we need normalized vectors
                        dirHeight.Norm();
                    }
                    //                    picture.Location = location - 0.5 * widthValue * dirWidth - 0.5 * heightValue * dirHeight;
                    picture.Location = location;
                }
            }
            else
            {
                picture.Location = location;
            }
            // provide the picture object with proper aspect ratio and scaling according to the scaling factor
            picture.DirectionWidth  = widthValue * dirWidth;
            picture.DirectionHeight = heightValue * dirHeight;
            // set the location of the object so that the center of the bitmap occures at the position of location
            // Since picture.Location is the lower left point of the object we must move it left and down
            // with half of it's size
            // diagonalPointDist = Geometry.Dist(picture.Location, picture.Location + picture.DirectionWidth + picture.DirectionHeight);
            return(true); // this was OK
        }
コード例 #2
0
 private bool SetFacePoint(GeoPoint p, SnapPointFinder.DidSnapModes didSnap)
 {
     if (didSnap == SnapPointFinder.DidSnapModes.DidSnapToFaceSurface)
     {
         Face f = base.LastSnapObject as Face;
         if (f != null)
         {
             GeoPoint2D p2d = f.Surface.PositionOf(p);
             faceVector = -f.Surface.GetNormal(p2d);
             selectDir();
             return(true);
         }
     }
     using (Frame.Project.Undo.ContextFrame(this))
     {
         if (vectorProperty != null)
         {
             vectorProperty.SetGeoVector(cancelVector);
         }
     }
     actualVector = cancelVector;
     return(false);
 }