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
25 \date September 2006 - January 2007
26 \brief BOUNCEXY has to be used with bounce_ball block
27 \see BOUNCEXY.sci in macros/scicos_blocks/Misc/
30 #include "scoMemoryScope.h"
31 #include "scoWindowScope.h"
33 #include "scoGetProperty.h"
34 #include "scoSetProperty.h"
35 #include "scicos_block4.h"
36 #include "ObjectStructure.h"
37 #include "DrawingBridge.h"
39 /** \fn bouncexy_draw(scicos_block * block, ScopeMemory ** pScopeMemory, int firstdraw)
40 \brief Function to draw or redraw the window
42 void bouncexy_draw(scicos_block * block, ScopeMemory ** pScopeMemory, int firstdraw)
44 scoGraphicalObject pAxes;
45 scoGraphicalObject pTemp;
51 double ymin, ymax, xmin, xmax;
54 int number_of_curves_by_subwin;
60 /*Retrieving Parameters*/
61 rpar = GetRparPtrs(block);
62 ipar = GetIparPtrs(block);
63 nipar = GetNipar(block);
67 win = 20000 + get_block_number() ;
71 number_of_curves_by_subwin = GetInPortRows(block,1);
73 size_balls = (double*)scicos_malloc(number_of_curves_by_subwin*sizeof(double));
75 for(i = 0 ; i < number_of_curves_by_subwin ; i++)
77 size_balls[i] = z[6*i+2];
78 if(radius_max < size_balls[i])
80 radius_max = size_balls[i];
88 colors = (int*)scicos_malloc(number_of_curves_by_subwin*sizeof(int));
89 for(i = 0 ; i < number_of_curves_by_subwin ; i++)
91 colors[i] = ipar[i+2];
96 scoInitScopeMemory(block->work,pScopeMemory, number_of_subwin, &number_of_curves_by_subwin);
98 /*Creating the Scope*/
99 scoInitOfWindow(*pScopeMemory, dimension, win, NULL, NULL, &xmin, &xmax, &ymin, &ymax, NULL, NULL);
100 if(scoGetScopeActivation(*pScopeMemory) == 1)
102 pTemp = scoGetPointerScopeWindow(*pScopeMemory);
103 pAxes = scoGetPointerAxes(*pScopeMemory,0);
105 pSUBWIN_FEATURE(pAxes)->isoview = TRUE;
107 (pSUBWIN_FEATURE(pAxes)->axes).axes_visible[0] = FALSE;
108 (pSUBWIN_FEATURE(pAxes)->axes).axes_visible[1] = FALSE;
110 sciSetIsBoxed(pAxes, FALSE);
111 sciSetPixmapMode(pTemp, TRUE);
113 pFIGURE_FEATURE(pTemp)->wshow = 1;
115 for(j = 0 ; j < number_of_curves_by_subwin ; j++)
117 scoAddSphereForShortDraw(*pScopeMemory, 0, j, size_balls[j], colors[j]);
119 scoAddRectangleForLongDraw(*pScopeMemory,0,0,xmin,(ymax-fabs(ymin)),fabs(xmax-xmin),fabs(ymax-ymin));
120 sciDrawObj(scoGetPointerLongDraw(*pScopeMemory,0,0));
123 scicos_free(size_balls);
127 /** \fn void bouncexy(scicos_block * block,int flag)
128 \brief the computational function
129 \param block A pointer to a scicos_block
130 \param flag An integer which indicates the state of the block (init, update, ending)
132 void bouncexy(scicos_block * block,int flag)
134 ScopeMemory * pScopeMemory;
135 scoGraphicalObject pShortDraw;
136 scoGraphicalObject pLongDraw;
146 bouncexy_draw(block,&pScopeMemory,1);
152 /*Retreiving Scope in the block->work*/
153 scoRetrieveScopeMemory(block->work,&pScopeMemory);
154 if(scoGetScopeActivation(pScopeMemory) == 1)
156 t = get_scicos_time();
157 /*If window has been destroyed we recreate it*/
158 if(scoGetPointerScopeWindow(pScopeMemory) == NULL)
160 bouncexy_draw(block,&pScopeMemory,0);
163 //Cannot be factorized depends of the scope
164 size_balls = (double*)scicos_malloc(scoGetNumberOfCurvesBySubwin(pScopeMemory,0)*sizeof(double));
165 z = GetDstate(block);
166 for(i = 0 ; i < scoGetNumberOfCurvesBySubwin(pScopeMemory,0) ; i++)
168 size_balls[i] = z[6*i+2];
170 u1 = GetRealInPortPtrs(block,1);
171 u2 = GetRealInPortPtrs(block,2);
172 for (i = 0 ; i < scoGetNumberOfCurvesBySubwin(pScopeMemory,0) ; i++)
174 pShortDraw = scoGetPointerShortDraw(pScopeMemory,0,i);
175 pLongDraw = scoGetPointerLongDraw(pScopeMemory,0,i);
176 pARC_FEATURE(pShortDraw)->x = u1[i]-size_balls[i]/2;
177 pARC_FEATURE(pShortDraw)->y = u2[i]+size_balls[i]/2;
181 sciSetUsedWindow(scoGetWindowID(pScopeMemory));
182 if (sciGetPixmapMode(scoGetPointerScopeWindow(pScopeMemory)))
184 C2F(dr)("xset","wshow",PI0,PI0,PI0,PI0,PI0,PI0,PD0,PD0,PD0,PD0,0L,0L);
185 sciDrawObj(scoGetPointerScopeWindow(pScopeMemory));
189 sciDrawObj(scoGetPointerScopeWindow(pScopeMemory));
192 scicos_free(size_balls);
198 scoRetrieveScopeMemory(block->work, &pScopeMemory);
199 if(scoGetScopeActivation(pScopeMemory) == 1)
201 sciSetUsedWindow(scoGetWindowID(pScopeMemory));
202 pShortDraw = sciGetCurrentFigure();
203 pFIGURE_FEATURE(pShortDraw)->user_data = NULL;
204 pFIGURE_FEATURE(pShortDraw)->size_of_user_data = 0;
206 scoFreeScopeMemory(block->work, &pScopeMemory);