3 * Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 * See the file ./license.txt
21 /*--------------------------------------------------------------------------*/
26 \date September 2006 - January 2007
27 \brief CSCOPXY is a scope in 2D which draw its input as a XY scope, there is no animation, everything is keep in memory instead of CANIMXY
28 \see CSCOPXY.sci in macros/scicos_blocks/Sinks/
30 /*--------------------------------------------------------------------------*/
31 #include "CurrentObjectsManagement.h"
32 #include "scoMemoryScope.h"
33 #include "scoWindowScope.h"
35 #include "scoGetProperty.h"
36 #include "scoSetProperty.h"
37 #include "scicos_block4.h"
38 #include "DrawingBridge.h"
39 #include "SetJavaProperty.h"
41 #include "dynlib_scicos_blocks.h"
42 /*--------------------------------------------------------------------------*/
43 /** \fn cscopxy_draw(scicos_block * block, ScopeMemory ** pScopeMemory, int firstdraw)
44 \brief Function to draw or redraw the window
46 SCICOS_BLOCKS_IMPEXP void cscopxy_draw(scicos_block * block, ScopeMemory ** pScopeMemory, int firstdraw)
48 int * ipar = NULL; //Integer Parameters
49 int color_flag = 0; //Flag on Color
53 int win = 0; //Windows ID : To give a name to the window
54 int buffer_size = 0; //Buffer Size
55 int win_pos[2]; //Position of the Window
56 int win_dim[2]; //Dimension of the Window
58 double * rpar = NULL; //Reals parameters
59 double xmin = 0., xmax = 0., ymin = 0., ymax = 0.; //Ymin and Ymax are vectors here
60 int number_of_subwin = 0;
61 int number_of_curves_by_subwin = 0;
65 scoGraphicalObject ShortDraw;
66 scoGraphicalObject LongDraw;
68 ipar = GetIparPtrs(block);
69 nipar = GetNipar(block);
70 rpar = GetRparPtrs(block);
73 buffer_size = ipar[2];
86 label = GetLabelPtrs(block);
89 number_of_curves_by_subwin = ipar[10]; //it is a trick to recognize the type of scope, not sure it is a good way because normally a curve is the combination of a short and a longdraw
92 scoInitScopeMemory(block->work,pScopeMemory, number_of_subwin, &number_of_curves_by_subwin);
93 scoSetShortDrawSize(*pScopeMemory,0,buffer_size);
94 scoSetLongDrawSize(*pScopeMemory,0,5000);
97 scoInitOfWindow(*pScopeMemory, dimension, win, win_pos, win_dim, &xmin, &xmax, &ymin, &ymax, NULL, NULL);
98 if(scoGetScopeActivation(*pScopeMemory) == 1)
100 for( i = 0 ; i < number_of_curves_by_subwin ; i++)
102 scoAddPolylineForShortDraw(*pScopeMemory,0,i,color[0]);
103 scoAddPolylineForLongDraw(*pScopeMemory,0,i,color[0]);
104 ShortDraw = scoGetPointerShortDraw(*pScopeMemory,0,i);
105 LongDraw = scoGetPointerLongDraw(*pScopeMemory,0,i);
106 /* Set ShortDraw properties */
107 sciSetLineWidth(ShortDraw, line_size);
108 sciSetMarkSize(ShortDraw, line_size);
109 /* Set LongDraw properties */
110 sciSetLineWidth(LongDraw, line_size);
111 sciSetMarkSize(LongDraw, line_size);
113 scoAddTitlesScope(*pScopeMemory,label,"x","y",NULL);
116 /* use only single buffering to be sure to draw on the screen */
117 if (scoGetPointerScopeWindow(*pScopeMemory) != NULL) {
118 sciSetJavaUseSingleBuffer(scoGetPointerScopeWindow(*pScopeMemory), TRUE);
121 /*--------------------------------------------------------------------------*/
122 /** \fn void cscopxy(scicos_block * block, int flag)
123 \brief the computational function
124 \param block A pointer to a scicos_block
125 \param flag An int which indicates the state of the block (init, update, ending)
127 SCICOS_BLOCKS_IMPEXP void cscopxy(scicos_block * block, int flag)
130 ScopeMemory * pScopeMemory = NULL;
131 double *u1 = NULL,*u2 = NULL;
132 scoGraphicalObject Pinceau;
136 /* State Machine Control */
141 cscopxy_draw(block,&pScopeMemory,1);
142 break; //Break of the switch condition don t forget it
143 } //End of Initialization
147 scoRetrieveScopeMemory(block->work,&pScopeMemory);
148 if(scoGetScopeActivation(pScopeMemory) == 1)
151 /* Charging Elements */
152 if (scoGetPointerScopeWindow(pScopeMemory) == NULL) // If the window has been destroyed we recreate it
154 cscopxy_draw(block,&pScopeMemory,0);
157 u1 = GetRealInPortPtrs(block,1);
158 u2 = GetRealInPortPtrs(block,2);
160 for(i = 0 ; i < scoGetNumberOfCurvesBySubwin(pScopeMemory,0); i++)
162 Pinceau = scoGetPointerShortDraw(pScopeMemory,0,i);
163 NbrPtsShort = pPOLYLINE_FEATURE(Pinceau)->n1;
164 pPOLYLINE_FEATURE(Pinceau)->pvx[NbrPtsShort] = u1[i];
165 pPOLYLINE_FEATURE(Pinceau)->pvy[NbrPtsShort] = u2[i];
166 pPOLYLINE_FEATURE(Pinceau)->n1++;
169 scoDrawScopeXYStyle(pScopeMemory);
171 break; //Break of the switch don t forget it !
172 }//End of stateupdate
174 //This case is activated when the simulation is done or when we close scicos
177 scoRetrieveScopeMemory(block->work, &pScopeMemory);
178 if(scoGetScopeActivation(pScopeMemory) == 1)
180 /*sciSetUsedWindow(scoGetWindowID(pScopeMemory));*/
182 /* Check if figure is still opened, otherwise, don't try to destroy it again. */
183 scoGraphicalObject figure = scoGetPointerScopeWindow(pScopeMemory);
186 for(i = 0 ; i < scoGetNumberOfCurvesBySubwin(pScopeMemory,0); i++)
188 Pinceau = scoGetPointerLongDraw(pScopeMemory,0,i);
189 forceRedraw(Pinceau);
192 //Here Pinceau = Window
193 /*Pinceau = sciGetCurrentFigure();*/
194 /*pFIGURE_FEATURE(Pinceau)->user_data = NULL;
195 pFIGURE_FEATURE(Pinceau)->size_of_user_data = 0;*/
196 clearUserData(figure);
198 /* restore double buffering */
200 sciSetJavaUseSingleBuffer(figure, FALSE);
204 scoFreeScopeMemory(block->work, &pScopeMemory);
205 break; //Break of the switch
207 //free the memory which is allocated at each turn by some variables
210 /*--------------------------------------------------------------------------*/