2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2011-2011 - DIGITEO - Bruno JOFRET
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
18 #include "ScilabView.hxx"
19 #include "CallGraphicController.hxx"
23 #include "createGraphicObject.h"
24 #include "setGraphicObjectProperty.h"
25 #include "getGraphicObjectProperty.h"
26 #include "graphicObjectProperties.h"
27 #include "getScilabJavaVM.h"
28 #include "deleteGraphicObject.h"
32 * C Wrapping functions
35 void ScilabNativeView__createObject(char const* pstId)
37 ScilabView::createObject(pstId);
40 void ScilabNativeView__deleteObject(char const*pstId)
42 ScilabView::deleteObject(pstId);
45 void ScilabNativeView__updateObject(char const* pstId, int iProperty)
47 ScilabView::updateObject(pstId, iProperty);
50 void ScilabNativeView__setCurrentFigure(char const* pstId)
52 ScilabView::setCurrentFigure(pstId);
55 void ScilabNativeView__setCurrentSubWin(char const* pstId)
57 ScilabView::setCurrentSubWin(pstId);
60 void ScilabNativeView__setCurrentObject(char const* pstId)
62 ScilabView::setCurrentObject(pstId);
65 int ScilabNativeView__getValidDefaultFigureId()
67 return ScilabView::getValidDefaultFigureId();
74 int ScilabView::getValidDefaultFigureId()
76 if (m_figureList.empty())
83 for (__figureList_iterator it = m_figureList.begin(); it != m_figureList.end(); ++it)
95 bool ScilabView::isEmptyFigureList()
97 return m_figureList.empty();
100 char const* ScilabView::getFigureFromIndex(int figNum)
102 __figureList_iterator it;
104 for (it = m_figureList.begin(); it != m_figureList.end(); ++it)
106 if (it->second == figNum)
108 return it->first.c_str();
114 bool ScilabView::existsFigureId(int id)
116 __figureList_iterator it;
118 for (it = m_figureList.begin(); it != m_figureList.end(); ++it)
120 if (it->second == id)
128 void ScilabView::getFiguresId(int ids[])
130 __figureList_iterator it;
131 int i = (int)(m_figureList.size() - 1);
133 for (it = m_figureList.begin(); it != m_figureList.end(); ++it, --i)
135 //std::cerr << "[ScilabView] DEBUG " << it->first << " <-> " << it->second << std::endl;
140 int ScilabView::getNbFigure(void)
142 return (int)m_figureList.size();
146 void ScilabView::createObject(char const* pstId)
148 //std::cerr << "[ScilabView] ++ createObject UID=" << pstId << std::endl;
150 int *piType = &iType;
152 getGraphicObjectProperty(pstId, __GO_TYPE__, jni_int, (void **)&piType);
153 if (iType != -1 && iType == __GO_FIGURE__)
155 m_figureList[pstId] = -1;
156 setCurrentFigure(pstId);
159 // Register object handle.
160 getObjectHandle(pstId);
163 void ScilabView::deleteObject(char const* pstId)
165 //std::cerr << "[ScilabView] -- deleteObject UID=" << pstId << std::endl;
167 int *piType = &iType;
168 char *pstParentUID = NULL;
170 getGraphicObjectProperty(pstId, __GO_TYPE__, jni_int, (void **)&piType);
173 ** If deleting a figure, remove from figure list.
175 if (iType != -1 && iType == __GO_FIGURE__)
177 m_figureList.erase(pstId);
181 ** If deleting current figure find another current one,
182 ** if there is no more figure : NULL
184 if (m_currentFigure == pstId) // Deleting current figure
186 char* pstrAxesUID = NULL;
188 if (getNbFigure() != 0)
190 m_currentFigure = m_figureList.rbegin()->first;
191 getGraphicObjectProperty(m_currentFigure.c_str(), __GO_SELECTED_CHILD__, jni_string, (void**)&pstrAxesUID);
192 setCurrentSubWin(pstrAxesUID);
196 setCurrentFigure(NULL);
197 setCurrentSubWin(NULL);
202 ** If deleting current entity, set parent as new current.
204 if (m_currentObject == pstId) // Deleting current object
206 getGraphicObjectProperty(pstId, __GO_PARENT__, jni_string, (void **)&pstParentUID);
207 setCurrentObject(pstParentUID);
210 // Remove the corresponding handle.
211 m_uidList.erase(m_handleList.find(pstId)->second);
212 m_handleList.erase(pstId);
214 deleteDataObject(pstId);
217 void ScilabView::updateObject(char const* pstId, int iProperty)
219 //std::cerr << "[ScilabView] == updateObject UID=" << pstId << " PROPERTY=" << pstProperty << std::endl;
222 ** Take care of update if the value update is ID and object type is a Figure I manage.
224 if (iProperty == __GO_ID__ && m_figureList.find(pstId) != m_figureList.end())
227 int *piNewId = &iNewId;
229 getGraphicObjectProperty(pstId, __GO_ID__, jni_int, (void **)&piNewId);
231 m_figureList[pstId] = iNewId;
232 //std::cerr << "### [ScilabView] updateMap UID=" << pstId << " id=" << iNewId << std::endl;
237 ** Register ScilabView to Controller.
238 ** Must be done after Graphics models are created.
240 void ScilabView::registerToController(void)
242 org_scilab_modules_graphic_objects::CallGraphicController::registerScilabView(getScilabJavaVM());
243 m_figureList.get_allocator().allocate(4096);
244 m_handleList.get_allocator().allocate(4096);
245 m_uidList.get_allocator().allocate(4096);
249 ** Reove ScilabView from Controller.
251 void ScilabView::unregisterToController(void)
253 org_scilab_modules_graphic_objects::CallGraphicController::unregisterScilabView(getScilabJavaVM());
257 ** Set Current Figure UID
259 void ScilabView::setCurrentFigure(char const* UID)
263 m_currentFigure = std::string();
267 m_currentFigure = UID;
272 ** Get Current Figure UID
274 char const* ScilabView::getCurrentFigure()
276 //std::cerr << "[ScilaView] currentFigure = " << (m_currentFigure == NULL ? "NULL !!" : m_currentFigure) << std::endl;
277 if (m_currentFigure.length() == 0)
281 return m_currentFigure.c_str();
285 ** Set Current Object UID
287 void ScilabView::setCurrentObject(char const* UID)
291 m_currentObject = std::string();
295 m_currentObject = UID;
300 ** Get Current Figure UID
302 char const* ScilabView::getCurrentObject()
304 //std::cerr << "[ScilaView] currentObject = " << m_currentObject << std::endl;
305 if (m_currentFigure.length() == 0)
309 return m_currentObject.c_str();
313 ** Set Current SubWin UID
315 void ScilabView::setCurrentSubWin(char const* UID)
319 m_currentSubWin = std::string();
323 m_currentSubWin = UID;
328 ** Get Current Figure UID
330 char const* ScilabView::getCurrentSubWin()
332 //std::cerr << "[ScilaView] currentSubWin = " << m_currentSubWin << std::endl;
333 if (m_currentSubWin.length() == 0)
337 return m_currentSubWin.c_str();
341 ** Scilab only can store long as handle
343 long ScilabView::getObjectHandle(char const* UID)
348 * std::cerr << "UID = " << UID << std::endl;
352 * std::cerr << "UID is null :-S" << std::endl;
354 * __handleList_iterator it2;
355 * std::cerr << "[DEBUG] +++ handleMap +++" << std::endl;
356 * for (it2 = m_handleList.begin() ; it2 != m_handleList.end() ; ++it2)
358 * std::cerr << "UID " << it2->first << " <-> handle " << it2->second << std::endl;
360 * std::cerr << "[DEBUG] +++ handleMap +++" << std::endl;
362 __handleList_iterator it = m_handleList.find(UID);
364 if (it != m_handleList.end())
369 // increase maximum value
370 // register new handle and return it.
372 m_handleList[UID] = m_topHandleValue;
373 m_uidList[m_topHandleValue] = UID;
375 return m_topHandleValue;
378 char const* ScilabView::getObjectFromHandle(long handle)
380 __uidList_iterator it = m_uidList.find(handle);
381 if (it == m_uidList.end())
386 return it->second.c_str();
389 char const* ScilabView::getFigureModel(void)
391 //std::cerr << "[ScilabView] getFigureModel = " << (m_figureModel == NULL ? "!! NULL !!" : m_figureModel) << std::endl;
392 if (m_figureModel.length() == 0)
396 return m_figureModel.c_str();
399 void ScilabView::setFigureModel(char const* UID)
404 char const* ScilabView::getAxesModel(void)
406 //std::cerr << "[ScilabView] getAxesModel = " << (m_axesModel == NULL ? "!! NULL !!" : m_axesModel) << std::endl;
407 if (m_axesModel.length() == 0)
411 return m_axesModel.c_str();
414 void ScilabView::setAxesModel(char const* UID)
420 ** Allocate static class variable.
422 ScilabView::__figureList ScilabView::m_figureList = *new __figureList();
423 ScilabView::__handleList ScilabView::m_handleList = *new __handleList();
424 ScilabView::__uidList ScilabView::m_uidList = *new __uidList();
425 long ScilabView::m_topHandleValue = 0;
426 std::string ScilabView::m_currentFigure;
427 std::string ScilabView::m_currentObject;
428 std::string ScilabView::m_currentSubWin;
429 std::string ScilabView::m_figureModel;
430 std::string ScilabView::m_axesModel;