ILOG
Welcome, Guest | Sign In


Blogs | Forums | Worldwide sites | Contact us

title element1
Product Info
Features
Tutorial
Datasheet
Supported platforms
Technical Forum
Solutions
Customers
News & Events
Press releases
Trial & Purchase
Demos
Evals
Contact info
Tutorial  

2D Graphics

You will first see how to use the basic objects that are used in every graphical application. The first step will show you how to create a graphic object, a manager, and a view.

Graphic objects
In the first step, you will create a filled rectangle. Some other basic shapes are available in the product, such as ellipses, rounded rectangles, lines, polylines, and polygons. To create a graphic object, you must provide information to display it. In this example, we must provide the position and the size of the rectangle.

Manager
The manager is a data structure that will contain and manage graphic objects. It has no visualization and needs a view to show its contents.

Views
The views can be attached to a manager to visualize its content. A view can be an independant window, or it can be integrated in another one.  In the first step, you will create a view as a new window, and attach it to the manager to see the graphic objects.

With this code, you just see this:
 
Download Step 1 executable (ZIP, 327 KB).
Let us present the code, beginning with the main part:
 
 IlvDisplay* display = new IlvDisplay("EvalKitStep1");
 IlvManager* manager = new IlvManager(display);
 IlvView* view = new IlvView(display, "View1", "Main View - Step 1", IlvRect(0,0,300,200));
The display class is used in every ILOG Views application as an interface between ILOG Views and the drawing system of your machine. On the creation of the display, you can specify a name that will be used to identify your application. You create an empty manager by simply providing the display, and you create a view as a new window. Some other view constructors are available to create it in different ways.
 
 manager->addView(view);
You attach the view to the manager. The view now shows the content of the manager, which is still empty.
 
 IlvFilledRectangle* rectangle = new IlvFilledRectangle(display, IlvRect(20,20,40,30));
 manager->addObject(rectangle);
"You create a graphic object: a filled rectangle, whose position is (20,20) and size is 40 by 30. Then it is added in the manager. As the manager has a view connected to it, our filled rectangle is now visible in the created view.
 
 view->setDestroyCallback(Quit);
The "setDestroyCallback" method allows you to define a callback function that will be called when the user clicks on the close window button.
In this sample, the Quit function is called to exit the application.

 
 IlvMainLoop();
This function call makes the application enter the event loop. ILOG Views is now taking all the events into account.
At this stage, some predefined keyboard actions are available:

 
Shift-Z Zoom in (zoom)
Shift-U Zoom out (unzoom)
left, right, up, down arrows Pan
Ctrl-C Copy selected object(s)
Ctrl-X Cut selected object(s)
Ctrl-V Paste object(s)

These actions are called accelerators. Other predefined accelerators are available, and we will see later that you can define your own accelerators, allowing you to trigger any kind of action on any kind of event (such as key press, mouse button press, or mouse movement).

Conclusion
This very simple code shows some important classes that are in almost every ILOG Views-based application. It is still very simple, so you cannot do anything with the displayed rectangle. We will see how to improve this example in the following steps.

See complete code.

Download source code.

Learn More
    Features  
    Charts  
    Maps  
    Graph Layout  
    Controls  
    Data Access  
    Gantt Chart  
     
ILOG JViews Diagrammer
(includes Graph Layout)
ILOG JViews Maps
ILOG JViews Gantt
ILOG JViews Charts
ILOG JViews Telecom Graphic Objects
ILOG JViews Maps for Defense
Customer Spotlight
   
     
 
 
element3