Display Feedbacks

The set of objects that implement the IDisplayFeedback interface gives you fine-grained control over customizing the visual feedback when using the mouse to form shapes on the screen display. You can direct the precise visual feedback for tasks, such as adding, moving, or reshaping features or graphic elements. The objects can also be used without creating any features or elements for a task, such as measuring the distance between two points. Typically, you would use the display feedback objects within code that handles the mouse events of a tool based on the ITool interface, such as OnMouseDown and OnMouseMove. Which mouse events to program depends on the task at hand. For example, when adding a new envelope, you would program the display feedback objects in the OnMouseDown, OnMouseMove, and OnMouseUp events. Or, when digitizing a new polygon, you would program the OnMouseDown, OnMouseMove, and OnDblClick events. When you are collecting points with the mouse to pass to the display feedbacks, you can use the ToMapPoint method on IDisplayTransformation to convert the current mouse location from device coordinates to map coordinates. Although the feedback objects (excluding the GroupFeedback object) all have common functionality, their behavior does vary. These variations can be divided as follows:
  1. Feedbacks that return a new geometry. The interfaces for these objects have a Stop method that returns the new geometry. These objects are NewEnvelopeFeedback, NewBezierCurveFeedback, NewDimensionFeedback, NewLineFeedback, NewPolygonFeedback, MoveEnvelopeFeedback, MoveLineFeedback, MovePointFeedback, MovePolygonFeedback, BezierMovePointFeedback, LineMovePointFeedback, PolygonMovePointFeedback, ReshapeFeedback, ResizeEnvelopeFeedback, and StretchLineFeedback.
  2. Feedbacks that are for display purposes only. The developer is required to calculate the new geometry. For example, you can use the start and end mouse locations and calculate the delta x and delta y shifts, and then you can update or create the geometry from this. These feedback objects are MoveGeometryFeedback, MoveImageFeedback, NewMultiPointFeedback, and VertexFeedback.
 
The objects are used within applications to allow graphic elements to be digitized and modified within the map (data view) and layout (layout view) and are also used by the ArcMap feature editing tools. Some of the feedback objects have a Constraint property that determines how the feedback behaves. These constraints can specify, for example, that a ResizeEnvelopeFeedback maintains the aspect ratio of the input Envelope. The details of these constraints are given with the individual feedbacks. The display feedback objects also provide some of the base functionality for the rubberband objects described earlier. You should use the rubberband objects first if they suit your requirements; select the display feedback objects if you want greater control over the user interface when modifying graphics or features. This greater control comes at the cost of more code.
The IDisplayFeedback interface is used to define the common operations on all of the display feedback operations. These include moving, symbolizing, and refreshing the display feedbacks as well as setting a display feedback object's Display property (for example, setting it to IActiveView::ScreenDisplay). The IDisplayFeedback interface is useful only in combination with one of the display feedback objects and its derived interfaces, for example, the NewPolygonFeedback object and its INewPolygonFeedback interface. Nearly all of the display feedback interfaces employ interface inheritance from IDisplayFeedback; hence, there is no need to use Caching to access its methods and properties. Typically, the Display and Symbol properties would be set when a display feedback object is initialized, while the MoveTo method would be called in a mouse move event. Setting the Symbol property is optional. If not set, a default symbol is used. The Refresh method is used to redraw the feedback after the window has been refreshed (for example, when it is activated again), and it should be called in response to the Tool's Refresh event. The hDC parameter, which is required by the Refresh method, is actually passed into the subroutine for you. In the following example, a check is first made to see if m_pNewPolyFeedback, which is a member variable NewPolygonFeedback object, has been instantiated yet, that is, if the user is currently using the feedback. If it has been instantiated, then the Refresh method is called.

[C#]
    private void Refresh(int hDC) 
    { 
     if (!(m_pNewPolyFeedback == null))
       { 
         m_pNewPolyFeedback.Refresh(hDC); 
       } 
    }
The following code example shows how to use the IDisplayFeedback interface with the INewEnvelopeFeedback interface to create a display feedback that will allow the user to add a new polygon. Note that this code simply demonstrates the visual feedback; further code is required if you wish to add that drawn shape as a map element or feature. The new envelope feedback object is declared as a member variable as follows:
[C#]
    private INewEnvelopeFeedback pNewEnvFeed;
Other objects are locally declared—pEnv as IEnvelope, pScreenDisp as IScreenDisplay, pLineSym as ISimpleLineSymbol, and pStartPoint and pMovePoint as IPoint. The following code would be placed in the OnMouseDown event to set up the Display and Symbol properties and to call INewEnvelopeFeedback::Start with the current mouse location in map units.
[C#]
    pNewEnvFeed = new NewEnvelopeFeedbackClass(); 
    pNewEnvFeed.Display = pScreenDisp; 
    pNewEnvFeed.Symbol = pLineSym as ISymbol; 
    pNewEnvFeed.Start(pStartPoint);
The following line of code would be placed in the OnMouseMove event to move the display feedback to the current mouse location in map units, using the MoveTo method from IDisplayFeedback.

 

[C#]
    pNewEnvFeed.MoveTo (pMovePoint)
The following line of code would be placed in the OnMouseUp event to return the result using the Stop method from INewEnvelopeFeedback.
[C#]
    pEnv = pNewEnvFeed.Stop;
 
以下是一个简单的用C语言编写的意见反馈系统的示例: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_FEEDBACKS 100 // 最大反馈数量 #define MAX_FEEDBACK_LENGTH 200 // 最大反馈长度 typedef struct { char content[MAX_FEEDBACK_LENGTH]; // 反馈内容 char email[MAX_FEEDBACK_LENGTH]; // 反馈者邮箱 } Feedback; Feedback feedbacks[MAX_FEEDBACKS]; // 反馈数组 int num_feedbacks = 0; // 反馈数量 void display_menu(); void add_feedback(); void list_feedbacks(); void save_feedbacks(); void load_feedbacks(); int main() { load_feedbacks(); // 从文件中读取反馈数据 int choice; do { display_menu(); // 显示菜单 scanf("%d", &choice); switch (choice) { case 1: add_feedback(); // 添加反馈 break; case 2: list_feedbacks(); // 列出所有反馈 break; case 3: save_feedbacks(); // 保存反馈数据到文件 break; case 4: printf("Goodbye!\n"); break; default: printf("Invalid choice. Please try again.\n"); break; } } while (choice != 4); return 0; } void display_menu() { printf("\n"); printf("1. Add feedback\n"); printf("2. List feedbacks\n"); printf("3. Save feedbacks\n"); printf("4. Exit\n"); printf("\n"); printf("Enter your choice: "); } void add_feedback() { if (num_feedbacks >= MAX_FEEDBACKS) { printf("Sorry, the feedback system is full. Please try again later.\n"); return; } Feedback feedback; printf("Enter your feedback (up to %d characters): ", MAX_FEEDBACK_LENGTH); scanf(" %[^\n]", feedback.content); printf("Enter your email address (up to %d characters): ", MAX_FEEDBACK_LENGTH); scanf(" %[^\n]", feedback.email); feedbacks[num_feedbacks++] = feedback; printf("Thank you for your feedback!\n"); } void list_feedbacks() { if (num_feedbacks == 0) { printf("There are no feedbacks to display.\n"); return; } printf("Feedbacks:\n"); for (int i = 0; i < num_feedbacks; i++) { printf("%d. %s\n", i + 1, feedbacks[i].content); printf(" From: %s\n", feedbacks[i].email); } } void save_feedbacks() { FILE *file = fopen("feedbacks.txt", "w"); if (!file) { printf("Error: could not open file for writing.\n"); return; } for (int i = 0; i < num_feedbacks; i++) { fprintf(file, "%s\n%s\n", feedbacks[i].content, feedbacks[i].email); } fclose(file); printf("Feedbacks saved to file.\n"); } void load_feedbacks() { FILE *file = fopen("feedbacks.txt", "r"); if (!file) { printf("No previous feedbacks found.\n"); return; } char content[MAX_FEEDBACK_LENGTH]; char email[MAX_FEEDBACK_LENGTH]; while (fgets(content, MAX_FEEDBACK_LENGTH, file) != NULL && fgets(email, MAX_FEEDBACK_LENGTH, file) != NULL) { content[strcspn(content, "\n")] = '\0'; // 删除换行符 email[strcspn(email, "\n")] = '\0'; // 删除换行符 Feedback feedback; strcpy(feedback.content, content); strcpy(feedback.email, email); feedbacks[num_feedbacks++] = feedback; } fclose(file); printf("Loaded %d feedbacks from file.\n", num_feedbacks); } ``` 该程序包括以下功能: - 添加反馈 - 列出所有反馈 - 保存反馈数据到文件 - 从文件中读取反馈数据 反馈数据保存在一个 `Feedback` 结构体数组中,其中包括反馈内容和反馈者的邮箱。程序最多支持存储100个反馈,每个反馈内容最长为200个字符。 用户可以通过菜单进行操作,每次操作后反馈数据会被保存到文件。当程序启动时,它会从文件中读取之前保存的反馈数据。 请注意,此示例仅用于演示目的,实际应用中可能需要添加更多的错误处理和输入验证。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值