No more no less than before : just instantiate a diagram.
Change-Id: Ib435a5b7027e73c88cebd3761546f47746c275b4
-/workspace/
+/workspace*/
.DS_Store
/.gitreview
_UpgradeReport_Files/
UpgradeLog.XML
+
# eclipse temp files
workspace/
.checkstyle
.cproject
.settings/
-# VIM ctags temp files
-tags
+# vim files
+/tags
# MacOS files
.DS_Store
};
template<typename T>
- update_status_t setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, T v)
+ update_status_t setObjectProperty(const ScicosID& uid, kind_t k, object_properties_t p, T v)
{
update_status_t status = m_instance.model.setObjectProperty(uid, k, p, v);
for (view_set_t::iterator iter = m_instance.allViews.begin(); iter != m_instance.allViews.end(); ++iter)
bool getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, ScicosID& v) const;
bool getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std::vector<double>& v) const;
bool getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std::vector<int>& v) const;
+ bool getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std::vector<bool>& v) const;
bool getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std::vector< std::string >& v) const;
bool getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std::vector<ScicosID>& v) const;
update_status_t setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std::string v);
update_status_t setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, const std::vector<double>& v);
update_status_t setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, const std::vector<int>& v);
+ update_status_t setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, const std::vector<bool>& v);
update_status_t setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, const std::vector< std::string >& v);
update_status_t setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, const std::vector<ScicosID>& v);
#ifndef ADAPTERS_HXX_
#define ADAPTERS_HXX_
+#include <utility>
#include <vector>
#include <string>
+#include "internal.hxx"
+#include "model/BaseObject.hxx"
+
+extern "C"
+{
+#include "dynlib_scicos.h"
+}
namespace org_scilab_modules_scicos
{
namespace view_scilab
/*
* Shared data between adapters
*/
-class Adapters
+class SCICOS_IMPEXP Adapters
{
public:
typedef enum
static Adapters& instance();
adapters_index_t lookup_by_typename(const std::wstring& name);
+ std::wstring get_typename(adapters_index_t index);
+ const model::BaseObject* descriptor(types::InternalType* v);
private:
#include <string>
+#include "../../includes/view_scilab/Adapters.hxx"
#include "gw_scicos.hxx"
#include "types.hxx"
#include "list.hxx"
#include "function.hxx"
-#include "view_scilab/Adapters.hxx"
#include "view_scilab/BaseAdapter.hxx"
#include "view_scilab/BlockAdapter.hxx"
#include "view_scilab/CprAdapter.hxx"
return mlist;
}
-types::Function::ReturnValue sci_scicos_new(types::typed_list &in, int _iRetCount, types::typed_list &out)
+types::Function::ReturnValue allocate(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
- if (in.size() < 1)
- {
- Scierror(999, _("%s: Wrong number of input arguments: At least %d expected.\n"), funame.data(), 1);
- return types::Function::Error;
- }
- if (_iRetCount > 1)
- {
- Scierror(999, _("%s: Wrong number of output arguments: %d expected.\n"), funame.data(), 1);
- return types::Function::Error;
- }
-
types::InternalType* type = in[0];
- if (type->getType() != types::InternalType::ScilabString)
- {
- Scierror(999, _("%s: Wrong type for input argument #%d: String expected.\n"), funame.data(), 1);
- return types::Function::Error;
- }
types::String* type_name = type->getAs<types::String>();
if (type_name->getRows() > 1)
return types::Function::OK;
}
+
+types::Function::ReturnValue get(types::Double* UIDs, int _iRetCount, types::typed_list &out)
+{
+ if (UIDs->getSize() != _iRetCount)
+ {
+ Scierror(999, _("%s: Wrong size for input argument #%d: %dx%d expected.\n"), funame.data(), 1, _iRetCount, 1);
+ return types::Function::Error;
+ }
+
+
+ Controller controller;
+ types::Function::ReturnValue retValue = types::Function::OK;
+ for (int i = 0; i < _iRetCount; ++i)
+ {
+ ScicosID uid = UIDs->get(i);
+
+ // create the associated object
+ model::BaseObject* o = controller.getObject(uid);
+ if (o == nullptr)
+ {
+ Scierror(999, _("%s: Wrong value for input argument #%d: invalid UID.\n"), funame.data(), 1);
+ retValue = types::Function::Error;
+ break;
+ }
+
+ switch (o->kind())
+ {
+ case DIAGRAM:
+ out.push_back(new view_scilab::DiagramAdapter(controller, static_cast<model::Diagram*>(controller.referenceObject(o))));
+ break;
+ case BLOCK:
+ out.push_back(new view_scilab::BlockAdapter(controller, static_cast<model::Block*>(controller.referenceObject(o))));
+ break;
+ case LINK:
+ out.push_back(new view_scilab::LinkAdapter(controller, static_cast<model::Link*>(controller.referenceObject(o))));
+ break;
+ default:
+ Scierror(999, _("%s: Wrong value for input argument #%d: not handled kind.\n"), funame.data(), 1);
+ retValue = types::Function::Error;
+ break;
+ }
+ }
+
+ if (retValue != types::Function::OK)
+ {
+ // something goes wrong, release the allocated data
+ for (types::typed_list::iterator it = out.begin(); it != out.end(); ++it)
+ {
+ delete *it;
+ }
+ }
+
+ return retValue;
+}
+
+types::Function::ReturnValue sci_scicos_new(types::typed_list &in, int _iRetCount, types::typed_list &out)
+{
+ if (in.size() < 1)
+ {
+ Scierror(999, _("%s: Wrong number of input arguments: At least %d expected.\n"), funame.data(), 1);
+ return types::Function::Error;
+ }
+ if (_iRetCount > 1)
+ {
+ Scierror(999, _("%s: Wrong number of output arguments: %d expected.\n"), funame.data(), 1);
+ return types::Function::Error;
+ }
+
+ types::InternalType* type = in[0];
+ switch (type->getType())
+ {
+ case types::InternalType::ScilabString:
+ return allocate(in, _iRetCount, out);
+ case types::InternalType::ScilabDouble:
+ return get(type->getAs<types::Double>(), _iRetCount, out);
+ default:
+ Scierror(999, _("%s: Wrong type for input argument #%d: String or ID expected.\n"), funame.data(), 1);
+ return types::Function::Error;
+ }
+}
+
#include <string>
+#include "../../includes/view_scilab/Adapters.hxx"
#include "gw_scicos.hxx"
#include "types.hxx"
#include "list.hxx"
#include "function.hxx"
-#include "view_scilab/Adapters.hxx"
#include "view_scilab/BaseAdapter.hxx"
#include "view_scilab/BlockAdapter.hxx"
#include "view_scilab/CprAdapter.hxx"
<ClInclude Include="..\..\includes\Controller.hxx" />
<ClInclude Include="..\..\includes\Model.hxx" />
<ClInclude Include="..\..\includes\model\BaseObject.hxx" />
+ <ClInclude Include="..\..\includes\view_scilab\Adapters.hxx" />
<ClInclude Include="..\..\includes\View.hxx" />
<ClInclude Include="..\cpp\createblklist.hxx" />
<ClInclude Include="..\cpp\extractblklist.hxx" />
<ClInclude Include="..\cpp\model\Diagram.hxx" />
<ClInclude Include="..\cpp\model\Link.hxx" />
<ClInclude Include="..\cpp\model\Port.hxx" />
- <ClInclude Include="..\cpp\view_scilab\Adapters.hxx" />
<ClInclude Include="..\cpp\view_scilab\BaseAdapter.hxx" />
<ClInclude Include="..\cpp\view_scilab\BlockAdapter.hxx" />
<ClInclude Include="..\cpp\view_scilab\CprAdapter.hxx" />
<ClInclude Include="..\cpp\view_scilab\TextAdapter.hxx">
<Filter>Header Files\MVC\view_scilab</Filter>
</ClInclude>
- <ClInclude Include="..\cpp\view_scilab\Adapters.hxx">
- <Filter>Header Files\MVC\view_scilab</Filter>
- </ClInclude>
<ClInclude Include="..\cpp\view_scilab\BaseAdapter.hxx">
<Filter>Header Files\MVC\view_scilab</Filter>
</ClInclude>
<ClInclude Include="..\..\includes\View.hxx">
<Filter>Header Files\MVC</Filter>
</ClInclude>
+ <ClInclude Include="..\..\includes\view_scilab\Adapters.hxx">
+ <Filter>Header Files\MVC\view_scilab</Filter>
+ </ClInclude>
<ClInclude Include="..\..\includes\Model.hxx">
<Filter>Header Files\MVC</Filter>
</ClInclude>
return false;
}
+bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std::vector<bool>& v) const
+{
+ model::BaseObject* baseObject = getObject(uid);
+ if (baseObject == nullptr)
+ {
+ return false;
+ }
+
+ if (k == ANNOTATION)
+ {
+ switch (p)
+ {
+ default:
+ break;
+ }
+ }
+ else if (k == BLOCK)
+ {
+ switch (p)
+ {
+ default:
+ break;
+ }
+ }
+ else if (k == DIAGRAM)
+ {
+ switch (p)
+ {
+ default:
+ break;
+ }
+ }
+ else if (k == LINK)
+ {
+ switch (p)
+ {
+ default:
+ break;
+ }
+ }
+ else if (k == PORT)
+ {
+ switch (p)
+ {
+ default:
+ break;
+ }
+ }
+ return false;
+}
+
bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std::vector<std::string>& v) const
{
model::BaseObject* baseObject = getObject(uid);
return FAIL;
}
+update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, const std::vector<bool>& v)
+{
+ model::BaseObject* baseObject = getObject(uid);
+ if (baseObject == nullptr)
+ {
+ return FAIL;
+ }
+
+ if (k == ANNOTATION)
+ {
+ switch (p)
+ {
+ default:
+ break;
+ }
+ }
+ else if (k == BLOCK)
+ {
+ switch (p)
+ {
+ default:
+ break;
+ }
+ }
+ else if (k == DIAGRAM)
+ {
+ switch (p)
+ {
+ default:
+ break;
+ }
+ }
+ else if (k == LINK)
+ {
+ switch (p)
+ {
+ default:
+ break;
+ }
+ }
+ else if (k == PORT)
+ {
+ switch (p)
+ {
+ default:
+ break;
+ }
+ }
+ return FAIL;
+}
+
update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properties_t p, const std::vector<std::string>& v)
{
model::BaseObject* baseObject = getObject(uid);
*
*/
+#include "../../../includes/view_scilab/Adapters.hxx"
+
#include <string>
#include <algorithm>
-#include "Adapters.hxx"
-
#include "BlockAdapter.hxx"
#include "CprAdapter.hxx"
#include "DiagramAdapter.hxx"
#include "LinkAdapter.hxx"
#include "ModelAdapter.hxx"
#include "ParamsAdapter.hxx"
+#include "ScsAdapter.hxx"
#include "StateAdapter.hxx"
#include "TextAdapter.hxx"
adapters.push_back(adapter_t(view_scilab::LinkAdapter::getSharedTypeStr(), LINK_ADAPTER));
adapters.push_back(adapter_t(view_scilab::ModelAdapter::getSharedTypeStr(), MODEL_ADAPTER));
adapters.push_back(adapter_t(view_scilab::ParamsAdapter::getSharedTypeStr(), PARAMS_ADAPTER));
+ adapters.push_back(adapter_t(view_scilab::ScsAdapter::getSharedTypeStr(), SCS_ADAPTER));
adapters.push_back(adapter_t(view_scilab::StateAdapter::getSharedTypeStr(), STATE_ADAPTER));
adapters.push_back(adapter_t(view_scilab::TextAdapter::getSharedTypeStr(), TEXT_ADAPTER));
return INVALID_ADAPTER;
}
+
+std::wstring Adapters::get_typename(Adapters::adapters_index_t kind)
+{
+ for (auto it : adapters)
+ {
+ if (it.kind == kind)
+ {
+ return it.name;
+ }
+ }
+
+ return L"";
+}
+
+
+const model::BaseObject* Adapters::descriptor(types::InternalType* v)
+{
+ const std::wstring& name = v->getShortTypeStr();
+ adapters_t::iterator it = std::lower_bound(adapters.begin(), adapters.end(), name);
+ if (v->isUserType() && it != adapters.end() && !(name < it->name))
+ {
+ switch (it->kind)
+ {
+ case BLOCK_ADAPTER:
+ return v->getAs<view_scilab::BlockAdapter>()->getAdaptee();
+ case CPR_ADAPTER:
+ return v->getAs<view_scilab::CprAdapter>()->getAdaptee();
+ case DIAGRAM_ADAPTER:
+ return v->getAs<view_scilab::DiagramAdapter>()->getAdaptee();
+ case GRAPHIC_ADAPTER:
+ return v->getAs<view_scilab::GraphicsAdapter>()->getAdaptee();
+ case LINK_ADAPTER:
+ return v->getAs<view_scilab::LinkAdapter>()->getAdaptee();
+ case MODEL_ADAPTER:
+ return v->getAs<view_scilab::ModelAdapter>()->getAdaptee();
+ case PARAMS_ADAPTER:
+ return v->getAs<view_scilab::ParamsAdapter>()->getAdaptee();
+ case SCS_ADAPTER:
+ return v->getAs<view_scilab::ScsAdapter>()->getAdaptee();
+ case STATE_ADAPTER:
+ return v->getAs<view_scilab::StateAdapter>()->getAdaptee();
+ case TEXT_ADAPTER:
+ return v->getAs<view_scilab::TextAdapter>()->getAdaptee();
+ }
+ }
+
+ return nullptr;
+}
+
} /* namespace view_scilab */
} /* namespace org_scilab_modules_scicos */
#include <vector>
#include <sstream>
+#include "../../../includes/view_scilab/Adapters.hxx"
#include "bool.hxx"
#include "double.hxx"
#include "user.hxx"
#include "utilities.hxx"
#include "Controller.hxx"
-#include "Adapters.hxx"
#include "model/BaseObject.hxx"
namespace org_scilab_modules_scicos
#include "adapters_utilities.hxx"
#include "Controller.hxx"
#include "DiagramAdapter.hxx"
-#include "Adapters.hxx"
+
+#include "view_scilab/Adapters.hxx"
#include "ParamsAdapter.hxx"
#include "BlockAdapter.hxx"
#include "LinkAdapter.hxx"
#include "user.hxx"
#include "Controller.hxx"
-#include "Adapters.hxx"
#include "ModelAdapter.hxx"
+
+#include "view_scilab/Adapters.hxx"
#include "DiagramAdapter.hxx"
#include "ports_management.hxx"
#include "utilities.hxx"
//
// This file is distributed under the same license as the Scilab package.
// =============================================================================
+// <-- CLI SHELL MODE -->
loadXcosLibs();
// sub-objects not mapped to the model
o = scicos_graphics()
from: 1 1 0
to: 2 1 1
scs_m.objs($+1) = lnk;
+// use scicos_new to retrieve and adapter from an uid
+blk2 = scicos_new(blk.modelID);
+clear blk
+blk2.model.rpar;
+clear blk2
// This file is distributed under the same license as the Scilab package.
// =============================================================================
+// <-- CLI SHELL MODE -->
+
loadXcosLibs();
// sub-objects not mapped to the model
lnk.to = [2 1 1]
scs_m.objs($+1) = lnk;
+// use scicos_new to retrieve and adapter from an uid
+blk2 = scicos_new(blk.modelID);
+
+clear blk
+blk2.model.rpar;
+clear blk2
+
sci_gateway/cpp/sci_Xcos.cpp \
sci_gateway/cpp/sci_warnBlockByUID.cpp \
sci_gateway/cpp/sci_closeXcosFromScilab.cpp \
- sci_gateway/cpp/sci_xcosDiagramToScilab.cpp \
sci_gateway/cpp/sci_xcosPalLoad.cpp \
sci_gateway/cpp/sci_xcosPalCategoryAdd.cpp \
sci_gateway/cpp/sci_xcosPalDelete.cpp \
sci_gateway/cpp/sci_xcosPalGet.cpp \
sci_gateway/cpp/sci_xcosConfigureXmlFile.cpp \
sci_gateway/cpp/sci_xcosAddToolsMenu.cpp \
- sci_gateway/cpp/sci_xcosUpdateBlock.cpp \
sci_gateway/cpp/sci_loadXcos.cpp \
sci_gateway/cpp/sci_xcosSimulationStarted.cpp
-I$(srcdir)/src/cpp/ \
-I$(srcdir)/src/c/ \
-I$(top_srcdir)/modules/scicos/includes/ \
- -I$(top_srcdir)/modules/dynamic_link/includes/ \
- -I$(top_srcdir)/modules/string/includes/ \
+ -I$(top_srcdir)/modules/dynamic_link/includes/ \
+ -I$(top_srcdir)/modules/string/includes/ \
-I$(top_srcdir)/modules/ast/includes/ast/ \
-I$(top_srcdir)/modules/ast/includes/exps/ \
-I$(top_srcdir)/modules/ast/includes/operations/ \
-I$(top_srcdir)/modules/ast/includes/system_env/ \
-I$(top_srcdir)/modules/ast/includes/types/ \
-I$(top_srcdir)/modules/ast/includes/analysis/ \
- -I$(top_srcdir)/modules/threads/includes/ \
- -I$(top_srcdir)/modules/console/includes/ \
+ -I$(top_srcdir)/modules/threads/includes/ \
+ -I$(top_srcdir)/modules/console/includes/ \
-I$(top_srcdir)/modules/jvm/includes/ \
-I$(top_srcdir)/modules/output_stream/includes/ \
-I$(top_srcdir)/modules/commons/src/jni/ \
am__objects_4 = sci_gateway/cpp/libscixcos_la-sci_Xcos.lo \
sci_gateway/cpp/libscixcos_la-sci_warnBlockByUID.lo \
sci_gateway/cpp/libscixcos_la-sci_closeXcosFromScilab.lo \
- sci_gateway/cpp/libscixcos_la-sci_xcosDiagramToScilab.lo \
sci_gateway/cpp/libscixcos_la-sci_xcosPalLoad.lo \
sci_gateway/cpp/libscixcos_la-sci_xcosPalCategoryAdd.lo \
sci_gateway/cpp/libscixcos_la-sci_xcosPalDelete.lo \
sci_gateway/cpp/libscixcos_la-sci_xcosPalGet.lo \
sci_gateway/cpp/libscixcos_la-sci_xcosConfigureXmlFile.lo \
sci_gateway/cpp/libscixcos_la-sci_xcosAddToolsMenu.lo \
- sci_gateway/cpp/libscixcos_la-sci_xcosUpdateBlock.lo \
sci_gateway/cpp/libscixcos_la-sci_loadXcos.lo \
sci_gateway/cpp/libscixcos_la-sci_xcosSimulationStarted.lo
am_libscixcos_la_OBJECTS = $(am__objects_3) $(am__objects_4)
sci_gateway/cpp/sci_Xcos.cpp \
sci_gateway/cpp/sci_warnBlockByUID.cpp \
sci_gateway/cpp/sci_closeXcosFromScilab.cpp \
- sci_gateway/cpp/sci_xcosDiagramToScilab.cpp \
sci_gateway/cpp/sci_xcosPalLoad.cpp \
sci_gateway/cpp/sci_xcosPalCategoryAdd.cpp \
sci_gateway/cpp/sci_xcosPalDelete.cpp \
sci_gateway/cpp/sci_xcosPalGet.cpp \
sci_gateway/cpp/sci_xcosConfigureXmlFile.cpp \
sci_gateway/cpp/sci_xcosAddToolsMenu.cpp \
- sci_gateway/cpp/sci_xcosUpdateBlock.cpp \
sci_gateway/cpp/sci_loadXcos.cpp \
sci_gateway/cpp/sci_xcosSimulationStarted.cpp
-I$(srcdir)/src/cpp/ \
-I$(srcdir)/src/c/ \
-I$(top_srcdir)/modules/scicos/includes/ \
- -I$(top_srcdir)/modules/dynamic_link/includes/ \
- -I$(top_srcdir)/modules/string/includes/ \
+ -I$(top_srcdir)/modules/dynamic_link/includes/ \
+ -I$(top_srcdir)/modules/string/includes/ \
-I$(top_srcdir)/modules/ast/includes/ast/ \
-I$(top_srcdir)/modules/ast/includes/exps/ \
-I$(top_srcdir)/modules/ast/includes/operations/ \
-I$(top_srcdir)/modules/ast/includes/system_env/ \
-I$(top_srcdir)/modules/ast/includes/types/ \
-I$(top_srcdir)/modules/ast/includes/analysis/ \
- -I$(top_srcdir)/modules/threads/includes/ \
- -I$(top_srcdir)/modules/console/includes/ \
+ -I$(top_srcdir)/modules/threads/includes/ \
+ -I$(top_srcdir)/modules/console/includes/ \
-I$(top_srcdir)/modules/jvm/includes/ \
-I$(top_srcdir)/modules/output_stream/includes/ \
-I$(top_srcdir)/modules/commons/src/jni/ \
sci_gateway/cpp/libscixcos_la-sci_closeXcosFromScilab.lo: \
sci_gateway/cpp/$(am__dirstamp) \
sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
-sci_gateway/cpp/libscixcos_la-sci_xcosDiagramToScilab.lo: \
- sci_gateway/cpp/$(am__dirstamp) \
- sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
sci_gateway/cpp/libscixcos_la-sci_xcosPalLoad.lo: \
sci_gateway/cpp/$(am__dirstamp) \
sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
sci_gateway/cpp/libscixcos_la-sci_xcosAddToolsMenu.lo: \
sci_gateway/cpp/$(am__dirstamp) \
sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
-sci_gateway/cpp/libscixcos_la-sci_xcosUpdateBlock.lo: \
- sci_gateway/cpp/$(am__dirstamp) \
- sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
sci_gateway/cpp/libscixcos_la-sci_loadXcos.lo: \
sci_gateway/cpp/$(am__dirstamp) \
sci_gateway/cpp/$(DEPDIR)/$(am__dirstamp)
@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_warnBlockByUID.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosAddToolsMenu.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosConfigureXmlFile.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosDiagramToScilab.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosPalCategoryAdd.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosPalDelete.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosPalDisable.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosPalLoad.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosPalMove.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosSimulationStarted.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosUpdateBlock.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscixcos_algo_la-loadStatus.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/cpp/$(DEPDIR)/libscixcos_algo_la-xcosUtilities.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/jni/$(DEPDIR)/libscixcos_algo_la-JavaController_wrap.Plo@am__quote@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libscixcos_la-sci_closeXcosFromScilab.lo `test -f 'sci_gateway/cpp/sci_closeXcosFromScilab.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_closeXcosFromScilab.cpp
-sci_gateway/cpp/libscixcos_la-sci_xcosDiagramToScilab.lo: sci_gateway/cpp/sci_xcosDiagramToScilab.cpp
-@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libscixcos_la-sci_xcosDiagramToScilab.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosDiagramToScilab.Tpo -c -o sci_gateway/cpp/libscixcos_la-sci_xcosDiagramToScilab.lo `test -f 'sci_gateway/cpp/sci_xcosDiagramToScilab.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosDiagramToScilab.cpp
-@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosDiagramToScilab.Tpo sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosDiagramToScilab.Plo
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='sci_gateway/cpp/sci_xcosDiagramToScilab.cpp' object='sci_gateway/cpp/libscixcos_la-sci_xcosDiagramToScilab.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libscixcos_la-sci_xcosDiagramToScilab.lo `test -f 'sci_gateway/cpp/sci_xcosDiagramToScilab.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosDiagramToScilab.cpp
-
sci_gateway/cpp/libscixcos_la-sci_xcosPalLoad.lo: sci_gateway/cpp/sci_xcosPalLoad.cpp
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libscixcos_la-sci_xcosPalLoad.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosPalLoad.Tpo -c -o sci_gateway/cpp/libscixcos_la-sci_xcosPalLoad.lo `test -f 'sci_gateway/cpp/sci_xcosPalLoad.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosPalLoad.cpp
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosPalLoad.Tpo sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosPalLoad.Plo
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libscixcos_la-sci_xcosAddToolsMenu.lo `test -f 'sci_gateway/cpp/sci_xcosAddToolsMenu.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosAddToolsMenu.cpp
-sci_gateway/cpp/libscixcos_la-sci_xcosUpdateBlock.lo: sci_gateway/cpp/sci_xcosUpdateBlock.cpp
-@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libscixcos_la-sci_xcosUpdateBlock.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosUpdateBlock.Tpo -c -o sci_gateway/cpp/libscixcos_la-sci_xcosUpdateBlock.lo `test -f 'sci_gateway/cpp/sci_xcosUpdateBlock.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosUpdateBlock.cpp
-@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosUpdateBlock.Tpo sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_xcosUpdateBlock.Plo
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='sci_gateway/cpp/sci_xcosUpdateBlock.cpp' object='sci_gateway/cpp/libscixcos_la-sci_xcosUpdateBlock.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o sci_gateway/cpp/libscixcos_la-sci_xcosUpdateBlock.lo `test -f 'sci_gateway/cpp/sci_xcosUpdateBlock.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_xcosUpdateBlock.cpp
-
sci_gateway/cpp/libscixcos_la-sci_loadXcos.lo: sci_gateway/cpp/sci_loadXcos.cpp
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libscixcos_la_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT sci_gateway/cpp/libscixcos_la-sci_loadXcos.lo -MD -MP -MF sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_loadXcos.Tpo -c -o sci_gateway/cpp/libscixcos_la-sci_loadXcos.lo `test -f 'sci_gateway/cpp/sci_loadXcos.cpp' || echo '$(srcdir)/'`sci_gateway/cpp/sci_loadXcos.cpp
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_loadXcos.Tpo sci_gateway/cpp/$(DEPDIR)/libscixcos_la-sci_loadXcos.Plo
+++ /dev/null
-//
-// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) 2009-2009 - DIGITEO - Vincent COUVERT <vincent.couvert@scilab.org>
-// Copyright (C) 2010-2010 - DIGITEO - Clément DAVID <clement.david@scilab.org>
-//
-// This file must be used under the terms of the CeCILL.
-// This source file is licensed as described in the file COPYING, which
-// you should have received as part of this distribution. The terms
-// are also available at
-// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
-//
-//
-
-function %diagram_xcos(scs_m)
- // Overload function when calling xcos with a diagram
- //
- // Calling Sequence
- // xcos(scs_m);
- //
- // Parameters
- // scs_m: the diagram instance
-
- // allocate a local copy
- scs_m = scs_m;
- // call xcos with the copy and name
- xcos(scs_m, "scs_m");
-endfunction
end
// import the real file
- convertStatus = xcosDiagramToScilab(fullPathName);
+ scs_m = scicos_diagram();
+ convertStatus = xcos(fullPathName, scs_m);
//return scs_m in Scilab environment
result = %t;
/*
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2010 - DIGITEO - Allan CORNET
- * Copyright (C) 2012 - Scilab Enterprises - Clement DAVID
+ * Copyright (C) 2012-2015 - Scilab Enterprises - Clement DAVID
* Copyright (C) 2015 - Scilab Enterprises - Paul Bignier
*
* This file must be used under the terms of the CeCILL.
#include "Xcos.hxx"
#include "loadStatus.hxx"
+#include "view_scilab/Adapters.hxx"
-#include "gw_xcos.hxx"
-
-#include "string.hxx"
-#include "mlist.hxx"
-#include "user.hxx"
+#include "types.hxx"
#include "function.hxx"
-#include "overload.hxx"
+#include "string.hxx"
+#include "gw_xcos.hxx"
-extern "C" {
+extern "C"
+{
#include "sci_malloc.h"
#include "getFullFilename.h"
#include "getScilabJavaVM.h"
}
using namespace org_scilab_modules_xcos;
+using namespace org_scilab_modules_scicos;
-static int callXcos(char* fname, char* file, char* var);
+static int callXcos(char* fname, char* file, long diagramId);
/*--------------------------------------------------------------------------*/
static char funname[] = "xcos";
*/
if (in.empty())
{
- callXcos(funname, nullptr, nullptr);
+ callXcos(funname, nullptr, ScicosID());
return types::Function::OK;
}
{
return types::Function::Error;
}
- if (callXcos(funname, file, nullptr))
+ if (callXcos(funname, file, ScicosID()))
{
return types::Function::Error;
}
/*
* xcos(scs_m) call
*/
- if (in.size() == 1 && (in[0]->isUserType() || in[0]->isMList())) // Kept MList for compatibility with Scilab 5
+ if (in.size() == 1 && in[0]->isUserType())
{
- if (in[0]->getShortTypeStr() != L"diagram")
+ const model::BaseObject* o = view_scilab::Adapters::instance().descriptor(in[0]);
+ if (o == nullptr || o->kind() != DIAGRAM)
{
Scierror(77, _("%s: Wrong type for input argument #%d: ""%s"" expected.\n"), funname, 1, "diagram");
return types::Function::Error;
}
- // overloaded by %diagram_xcos.sci
- std::wstring wstFuncName = L"%" + in[0]->getShortTypeStr() + L"_xcos";
- types::typed_list out;
- types::Function::ReturnValue ret = Overload::call(wstFuncName, in, _iRetCount, out);
-
+ if (callXcos(funname, nullptr, static_cast<long>(o->id())))
+ {
+ return types::Function::Error;
+ }
return types::Function::OK;
}
+ // we finished the 1-argument handling ; short-cut return with a clear error message
+ if (in.size() == 1)
+ {
+ Scierror(999, _("%s: Wrong type for input argument #%d: string or ""%s"" expected.\n"), funname, 1, "diagram");
+ return types::Function::Error;
+ }
+
+
/*
- * xcos(scs_m, "scs_m") call (usually from the overload macro)
+ * xcos("file.zcos", scs_m) call ; load the file into an existing diagram
*/
- if (in.size() == 2 && in[0]->isMList()) // For compatibility with Scilab 5
+ if (in.size() == 2 &&
+ in[0]->isString() &&
+ in[1]->isUserType())
{
- if (in[1]->isString() == false)
+ if (in[0]->getAs<types::String>()->getSize() != 1)
{
- Scierror(999, _("%s: Wrong type for input argument #%d : A string expected.\n"), funname, 2);
+ Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), funname, 1);
return types::Function::Error;
}
- types::String* arg2 = in[1]->getAs<types::String>();
- if (arg2->isScalar() == false)
+ const model::BaseObject* o = view_scilab::Adapters::instance().descriptor(in[1]);
+ if (o == nullptr || o->kind() != DIAGRAM)
{
- Scierror(999, _("%s: Wrong size for input argument #%d : A single string expected.\n"), funname, 2);
+ Scierror(999, _("%s: Wrong type for input argument #%d: ""%s"" expected.\n"), funname, 2, "diagram");
return types::Function::Error;
}
- char* c_str = wide_string_to_UTF8(arg2->get(0));
- int ret = callXcos(funname, nullptr, c_str);
- FREE(c_str);
- if (ret == 1)
- {
- return types::Function::Error;
- }
- else
- {
- return types::Function::OK;
- }
- }
- if (in.size() == 2 && in[0]->isUserType())
- {
- if (in[1]->isString() == false)
+ char* c_str = wide_string_to_UTF8(in[0]->getAs<types::String>()->get(0));
+ char* file = getFullFilename(c_str);
+ if (file == nullptr)
{
- Scierror(999, _("%s: Wrong type for input argument #%d : A string expected.\n"), funname, 2);
+ FREE(c_str);
return types::Function::Error;
}
- types::String* arg2 = in[1]->getAs<types::String>();
- if (arg2->isScalar() == false)
+ if (callXcos(funname, c_str, static_cast<long>(o->id())))
{
- Scierror(999, _("%s: Wrong size for input argument #%d : A single string expected.\n"), funname, 2);
+ FREE(c_str);
return types::Function::Error;
}
-
- char* c_str = wide_string_to_UTF8(arg2->get(0));
- int ret = callXcos(funname, nullptr, c_str);
FREE(c_str);
- if (ret == 1)
- {
- return types::Function::Error;
- }
- else
- {
- return types::Function::OK;
- }
+ return types::Function::OK;
}
-
/*
- * If not returned yet, display the error message.
+ * If not returned yet, display a generic error message.
*/
- Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), funname, 1);
+ Scierror(999, _("%s: Wrong type for input argument #%d: string or ""%s"" expected.\n"), funname, 1, "diagram");
return types::Function::Error;
}
/*--------------------------------------------------------------------------*/
-static int callXcos(char *fname, char* file, char* var)
+static int callXcos(char *fname, char* file, long diagramId)
{
set_loaded_status(XCOS_CALLED);
try
{
- Xcos::xcos(getScilabJavaVM(), file, var);
+ Xcos::xcos(getScilabJavaVM(), file, diagramId);
}
catch (GiwsException::JniCallMethodException &exception)
{
{
FREE(file);
}
- if (var)
- {
- FREE(var);
- }
return 1;
}
catch (GiwsException::JniException &exception)
{
FREE(file);
}
- if (var)
- {
- FREE(var);
- }
return 1;
}
{
FREE(file);
}
- if (var)
- {
- FREE(var);
- }
return 0;
}
+
+++ /dev/null
-/*
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) DIGITEO - 2009-2009 - Antoine ELIAS <antoine.elias@scilab.org>
- * Copyright (C) DIGITEO - 2009-2010 - Clément DAVID <clement.david@scilab.org>
- *
- * This file must be used under the terms of the CeCILL.
- * This source file is licensed as described in the file COPYING, which
- * you should have received as part of this distribution. The terms
- * are also available at
- * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
- *
- */
-/*--------------------------------------------------------------------------*/
-#include "Xcos.hxx"
-#include "GiwsException.hxx"
-#include "loadStatus.hxx"
-
-extern "C"
-{
-#include "gw_xcos.h"
-#include "api_scilab.h"
-#include "localization.h"
-#include "Scierror.h"
-#include "sci_malloc.h"
-#include "freeArrayOfString.h"
-#include "getScilabJavaVM.h"
-}
-/*--------------------------------------------------------------------------*/
-using namespace org_scilab_modules_xcos;
-
-/*--------------------------------------------------------------------------*/
-int sci_xcosDiagramToScilab(char *fname, void *pvApiCtx)
-{
- CheckRhs(1, 1);
- CheckLhs(0, 1);
-
- SciErr sciErr;
-
- int iRows1 = 0;
- int iCols1 = 0;
- int iLen1 = 0;
- int *piAddr1 = NULL;
- char *pstXcosFile = NULL;
-
- //get xcos filename
- sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr1);
- if (sciErr.iErr)
- {
- printError(&sciErr, 0);
- Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
- return 0;
- }
-
- //get xcos filename matrix dimension
- sciErr = getMatrixOfString(pvApiCtx, piAddr1, &iRows1, &iCols1, NULL, NULL);
- if (sciErr.iErr)
- {
- printError(&sciErr, 0);
- Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
- return 0;
- }
-
- if (iRows1 != 1 || iCols1 != 1)
- {
- Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
- }
-
- //get xcos filename length
- sciErr = getMatrixOfString(pvApiCtx, piAddr1, &iRows1, &iCols1, &iLen1, NULL);
- if (sciErr.iErr)
- {
- printError(&sciErr, 0);
- Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
- return 0;
- }
-
- pstXcosFile = (char*) MALLOC(sizeof(char) * (iLen1 + 1)); //+ 1 for null termination
- //get xcos filename
- sciErr = getMatrixOfString(pvApiCtx, piAddr1, &iRows1, &iCols1, &iLen1, &pstXcosFile);
- if (sciErr.iErr)
- {
- printError(&sciErr, 0);
- Scierror(999, _("%s: Can not read input argument #%d.\n"), fname, 1);
- return 0;
- }
-
- /*
- * Call the Java implementation
- */
- int iRet = 0;
-
- set_loaded_status(XCOS_CALLED);
- try
- {
- iRet = Xcos::xcosDiagramToScilab(getScilabJavaVM(), pstXcosFile);
- }
- catch (GiwsException::JniCallMethodException &exception)
- {
- Scierror(999, "%s: %s\n", fname, exception.getJavaDescription().c_str());
- return 0;
- }
- catch (GiwsException::JniException &exception)
- {
- Scierror(999, "%s: %s\n", fname, exception.whatStr().c_str());
- return 0;
- }
-
- if (iRet != 0)
- {
- //manage error
- iRet = 1;
- }
-
- double dblResult = iRet;
-
- sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, 1, 1, &dblResult);
- if (sciErr.iErr)
- {
- printError(&sciErr, 0);
- Scierror(999, _("%s: Memory allocation error.\n"), fname);
- return 0;
- }
-
- LhsVar(1) = Rhs + 1;
- PutLhsVar();
- return 0;
-}
-
-/*--------------------------------------------------------------------------*/
*/
#include "Palette.hxx"
+#include "Controller.hxx"
#include "GiwsException.hxx"
#include "xcosUtilities.hxx"
#include "loadStatus.hxx"
}
using namespace org_scilab_modules_xcos_palette;
+using namespace org_scilab_modules_scicos;
int sci_xcosPalGenerateIcon(char *fname, void* pvApiCtx)
{
set_loaded_status(XCOS_CALLED);
try
{
- Palette::generatePaletteIcon(getScilabJavaVM(), iconPath);
+ Controller controller;
+ Palette::generatePaletteIcon(getScilabJavaVM(), controller.createObject(DIAGRAM), iconPath);
}
catch (GiwsException::JniCallMethodException &exception)
{
+++ /dev/null
-/*
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) Scilab Enterprises - 2011 - Clément DAVID
- *
- * This file must be used under the terms of the CeCILL.
- * This source file is licensed as described in the file COPYING, which
- * you should have received as part of this distribution. The terms
- * are also available at
- * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
- *
- */
-
-#include "Xcos.hxx"
-#include "GiwsException.hxx"
-#include "xcosUtilities.hxx"
-#include "loadStatus.hxx"
-
-extern "C"
-{
-#include "gw_xcos.h"
-#include "api_scilab.h"
-#include "localization.h"
-#include "Scierror.h"
-#include "sci_malloc.h"
-#include "getScilabJavaVM.h"
-}
-
-using namespace org_scilab_modules_xcos;
-
-int sci_xcosUpdateBlock(char *fname, void *pvApiCtx)
-{
- CheckRhs(2, 2);
- CheckLhs(0, 1);
-
- char *hdf5File = NULL;
-
- if (readSingleString(pvApiCtx, 1, &hdf5File, fname))
- {
- return 0;
- }
-
- /* Call the java implementation */
- set_loaded_status(XCOS_CALLED);
- try
- {
- Xcos::updateBlock(getScilabJavaVM(), hdf5File);
-
- FREE(hdf5File);
- hdf5File = NULL;
- }
- catch (GiwsException::JniCallMethodException &exception)
- {
- Scierror(999, "%s: %s\n", fname, exception.getJavaDescription().c_str());
-
- FREE(hdf5File);
- hdf5File = NULL;
- return 0;
- }
- catch (GiwsException::JniException &exception)
- {
- Scierror(999, "%s: %s\n", fname, exception.whatStr().c_str());
-
- FREE(hdf5File);
- hdf5File = NULL;
- return 0;
- }
-
- PutLhsVar();
- return 0;
-}
<module name="xcos">
<gateway name="sci_warnBlockByUID" function="warnBlockByUID" type="0" />
<gateway name="sci_closeXcosFromScilab" function="closeXcos" type="0" />
- <gateway name="sci_xcosDiagramToScilab" function="xcosDiagramToScilab" type="0" />
<gateway name="sci_xcosPalLoad" function="xcosPalLoad" type="0" />
<gateway name="sci_xcosPalCategoryAdd" function="xcosPalCategoryAdd" type="0" />
<gateway name="sci_xcosPalDelete" function="xcosPalDelete" type="0" />
<gateway name="sci_xcosPalGenerateIcon" function="xcosPalGenerateIcon" type="0" />
<gateway name="sci_xcosConfigureXmlFile" function="xcosConfigureXmlFile" type="0" />
<gateway name="sci_xcosAddToolsMenu" function="xcosAddToolsMenu" type="0" />
- <gateway name="sci_xcosUpdateBlock" function="xcosUpdateBlock" type="0" />
<gateway name="sci_loadXcos" function="loadXcos" type="0" />
<gateway name="sci_xcosSimulationStarted" function="xcosSimulationStarted" type="0" />
<gateway name="sci_xcosPalGet" function="xcosPalGet" type="0" />
<ClCompile Include="..\..\sci_gateway\cpp\sci_warnBlockByUID.cpp" />
<ClCompile Include="..\..\sci_gateway\cpp\sci_Xcos.cpp" />
<ClCompile Include="..\..\sci_gateway\cpp\sci_xcosConfigureXmlFile.cpp" />
- <ClCompile Include="..\..\sci_gateway\cpp\sci_xcosDiagramToScilab.cpp" />
<ClCompile Include="..\..\sci_gateway\cpp\sci_xcosPalCategoryAdd.cpp" />
<ClCompile Include="..\..\sci_gateway\cpp\sci_xcosPalDelete.cpp" />
<ClCompile Include="..\..\sci_gateway\cpp\sci_xcosPalDisable.cpp" />
<ClCompile Include="..\..\sci_gateway\cpp\sci_xcosPalMove.cpp" />
<ClCompile Include="..\..\sci_gateway\cpp\sci_xcosPalGet.cpp" />
<ClCompile Include="..\..\sci_gateway\cpp\sci_xcosAddToolsMenu.cpp" />
- <ClCompile Include="..\..\sci_gateway\cpp\sci_xcosUpdateBlock.cpp" />
<ClCompile Include="..\..\sci_gateway\cpp\sci_loadXcos.cpp" />
<ClCompile Include="..\..\sci_gateway\cpp\sci_xcosSimulationStarted.cpp" />
<ClCompile Include="..\jni\Xcos.cpp" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
<ClCompile Include="..\..\sci_gateway\cpp\sci_xcosConfigureXmlFile.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="..\..\sci_gateway\cpp\sci_xcosDiagramToScilab.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="..\..\sci_gateway\cpp\sci_xcosPalCategoryAdd.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\sci_gateway\cpp\sci_xcosAddToolsMenu.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="..\..\sci_gateway\cpp\sci_xcosUpdateBlock.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="..\..\sci_gateway\cpp\sci_loadXcos.cpp">
<Filter>Source Files</Filter>
</ClCompile>
return JavaControllerJNI.Controller_getObjectProperty__SWIG_6(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfInt.getCPtr(v), v);
}
+ public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfBool v) {
+ return JavaControllerJNI.Controller_getObjectProperty__SWIG_7(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfBool.getCPtr(v), v);
+ }
+
public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfDouble v) {
- return JavaControllerJNI.Controller_getObjectProperty__SWIG_7(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfDouble.getCPtr(v), v);
+ return JavaControllerJNI.Controller_getObjectProperty__SWIG_8(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfDouble.getCPtr(v), v);
}
public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfString v) {
- return JavaControllerJNI.Controller_getObjectProperty__SWIG_8(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfString.getCPtr(v), v);
+ return JavaControllerJNI.Controller_getObjectProperty__SWIG_9(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfString.getCPtr(v), v);
}
public boolean getObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfScicosID v) {
- return JavaControllerJNI.Controller_getObjectProperty__SWIG_9(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfScicosID.getCPtr(v), v);
+ return JavaControllerJNI.Controller_getObjectProperty__SWIG_10(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfScicosID.getCPtr(v), v);
}
public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, int v) {
return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_6(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfInt.getCPtr(v), v)];
}
+ public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfBool v) {
+ return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_7(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfBool.getCPtr(v), v)];
+ }
+
public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfDouble v) {
- return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_7(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfDouble.getCPtr(v), v)];
+ return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_8(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfDouble.getCPtr(v), v)];
}
public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfString v) {
- return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_8(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfString.getCPtr(v), v)];
+ return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_9(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfString.getCPtr(v), v)];
}
public UpdateStatus setObjectProperty(long uid, Kind k, ObjectProperties p, VectorOfScicosID v) {
- return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_9(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfScicosID.getCPtr(v), v)];
+ return UpdateStatus.class.getEnumConstants()[JavaControllerJNI.Controller_setObjectProperty__SWIG_10(swigCPtr, this, uid, k.ordinal(), p.ordinal(), VectorOfScicosID.getCPtr(v), v)];
}
}
package org.scilab.modules.xcos;
-import java.util.ArrayList;
+import java.util.Map;
+import java.util.TreeMap;
public class JavaController extends Controller {
// will contains all registered JavaViews to prevent garbage-collection
- private static ArrayList<View> references = new ArrayList<View>();
+ private static Map<String, View> references = new TreeMap<String, View>();
- private static long add_reference(View v) {
- references.add(v);
+ private static long add_reference(String name, View v) {
+ references.put(name, v);
return View.getCPtr(v);
}
private static View remove_reference(View v) {
- references.remove(v);
+ references.values().remove(v);
return v;
}
+ public static View lookup_view(String name) {
+ return references.get(name);
+ }
+
public static void register_view(String name, View view) {
- JavaControllerJNI.register_view(name, add_reference(view), view);
+ JavaControllerJNI.register_view(name, add_reference(name, view), view);
}
public static void unregister_view(View view) {
public final static native boolean Controller_getObjectProperty__SWIG_4(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, String[] jarg5);
public final static native boolean Controller_getObjectProperty__SWIG_5(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long[] jarg5);
public final static native boolean Controller_getObjectProperty__SWIG_6(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfInt jarg5_);
- public final static native boolean Controller_getObjectProperty__SWIG_7(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfDouble jarg5_);
- public final static native boolean Controller_getObjectProperty__SWIG_8(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfString jarg5_);
- public final static native boolean Controller_getObjectProperty__SWIG_9(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfScicosID jarg5_);
+ public final static native boolean Controller_getObjectProperty__SWIG_7(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfBool jarg5_);
+ public final static native boolean Controller_getObjectProperty__SWIG_8(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfDouble jarg5_);
+ public final static native boolean Controller_getObjectProperty__SWIG_9(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfString jarg5_);
+ public final static native boolean Controller_getObjectProperty__SWIG_10(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfScicosID jarg5_);
public final static native int Controller_setObjectProperty__SWIG_1(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, int jarg5);
public final static native int Controller_setObjectProperty__SWIG_2(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, boolean jarg5);
public final static native int Controller_setObjectProperty__SWIG_3(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, double jarg5);
public final static native int Controller_setObjectProperty__SWIG_4(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, String jarg5);
public final static native int Controller_setObjectProperty__SWIG_5(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5);
public final static native int Controller_setObjectProperty__SWIG_6(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfInt jarg5_);
- public final static native int Controller_setObjectProperty__SWIG_7(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfDouble jarg5_);
- public final static native int Controller_setObjectProperty__SWIG_8(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfString jarg5_);
- public final static native int Controller_setObjectProperty__SWIG_9(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfScicosID jarg5_);
- public final static native long new_VectorOfDouble__SWIG_0();
- public final static native long new_VectorOfDouble__SWIG_1(long jarg1);
- public final static native long VectorOfDouble_size(long jarg1, VectorOfDouble jarg1_);
- public final static native long VectorOfDouble_capacity(long jarg1, VectorOfDouble jarg1_);
- public final static native void VectorOfDouble_reserve(long jarg1, VectorOfDouble jarg1_, long jarg2);
- public final static native boolean VectorOfDouble_isEmpty(long jarg1, VectorOfDouble jarg1_);
- public final static native void VectorOfDouble_clear(long jarg1, VectorOfDouble jarg1_);
- public final static native void VectorOfDouble_add(long jarg1, VectorOfDouble jarg1_, double jarg2);
- public final static native double VectorOfDouble_get(long jarg1, VectorOfDouble jarg1_, int jarg2);
- public final static native void VectorOfDouble_set(long jarg1, VectorOfDouble jarg1_, int jarg2, double jarg3);
- public final static native void delete_VectorOfDouble(long jarg1);
+ public final static native int Controller_setObjectProperty__SWIG_7(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfBool jarg5_);
+ public final static native int Controller_setObjectProperty__SWIG_8(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfDouble jarg5_);
+ public final static native int Controller_setObjectProperty__SWIG_9(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfString jarg5_);
+ public final static native int Controller_setObjectProperty__SWIG_10(long jarg1, Controller jarg1_, long jarg2, int jarg3, int jarg4, long jarg5, VectorOfScicosID jarg5_);
public final static native long new_VectorOfInt__SWIG_0();
public final static native long new_VectorOfInt__SWIG_1(long jarg1);
public final static native long VectorOfInt_size(long jarg1, VectorOfInt jarg1_);
public final static native boolean VectorOfBool_get(long jarg1, VectorOfBool jarg1_, int jarg2);
public final static native void VectorOfBool_set(long jarg1, VectorOfBool jarg1_, int jarg2, boolean jarg3);
public final static native void delete_VectorOfBool(long jarg1);
+ public final static native long new_VectorOfDouble__SWIG_0();
+ public final static native long new_VectorOfDouble__SWIG_1(long jarg1);
+ public final static native long VectorOfDouble_size(long jarg1, VectorOfDouble jarg1_);
+ public final static native long VectorOfDouble_capacity(long jarg1, VectorOfDouble jarg1_);
+ public final static native void VectorOfDouble_reserve(long jarg1, VectorOfDouble jarg1_, long jarg2);
+ public final static native boolean VectorOfDouble_isEmpty(long jarg1, VectorOfDouble jarg1_);
+ public final static native void VectorOfDouble_clear(long jarg1, VectorOfDouble jarg1_);
+ public final static native void VectorOfDouble_add(long jarg1, VectorOfDouble jarg1_, double jarg2);
+ public final static native double VectorOfDouble_get(long jarg1, VectorOfDouble jarg1_, int jarg2);
+ public final static native void VectorOfDouble_set(long jarg1, VectorOfDouble jarg1_, int jarg2, double jarg3);
+ public final static native void delete_VectorOfDouble(long jarg1);
public final static native long new_VectorOfString__SWIG_0();
public final static native long new_VectorOfString__SWIG_1(long jarg1);
public final static native long VectorOfString_size(long jarg1, VectorOfString jarg1_);
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2015 - Scilab Enterprises - Clement DAVID
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ *
+ */
+
+package org.scilab.modules.xcos;
+
+import org.scilab.modules.graph.utils.StyleMap;
+
+/**
+ * Update the source block when the interface function change.
+ */
+public final class UpdateStyleFromInterfunctionAdapter extends XcosViewListener {
+ private UpdateStyleFromInterfunctionAdapter() { }
+
+ /**
+ * Put the interfunction at the start of the style map to preserve
+ * style modification.
+ *
+ * oldStyle="SUPER_f;fillColor=red" newStyle="DSUPER;fillColor=red"
+ *
+ * and not newStyle="fillColor=red;DSUPER"
+ */
+ @Override
+ public void propertyUpdated(long uid, Kind kind, ObjectProperties property, UpdateStatus status) {
+
+ // prevent any unrelated property change, safety code
+ if (property != ObjectProperties.INTERFACE_FUNCTION && property != ObjectProperties.STYLE) {
+ return;
+ }
+
+ JavaController controller = new JavaController();
+
+ String[] interfaceFunction = new String[0];
+ controller.getObjectProperty(uid, kind, ObjectProperties.INTERFACE_FUNCTION, interfaceFunction);
+
+ String[] style = new String[0];
+ controller.getObjectProperty(uid, kind, ObjectProperties.STYLE, style);
+
+
+ final StyleMap styleMap = new StyleMap(interfaceFunction[0]);
+ styleMap.putAll(style[0]);
+
+ controller.setObjectProperty(uid, kind, ObjectProperties.STYLE, styleMap.toString());
+ }
+}
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import org.scilab.modules.localization.Messages;
import org.scilab.modules.xcos.actions.ExternalAction;
import org.scilab.modules.xcos.actions.StopAction;
-import org.scilab.modules.xcos.block.BasicBlock;
-import org.scilab.modules.xcos.block.SuperBlock;
import org.scilab.modules.xcos.configuration.ConfigurationManager;
import org.scilab.modules.xcos.configuration.model.DocumentType;
import org.scilab.modules.xcos.graph.DiagramComparator;
-import org.scilab.modules.xcos.graph.SuperBlockDiagram;
import org.scilab.modules.xcos.graph.XcosDiagram;
-import org.scilab.modules.xcos.io.XcosFileType;
-import org.scilab.modules.xcos.io.scicos.ScicosFormatException;
-import org.scilab.modules.xcos.io.scicos.ScilabDirectHandler;
import org.scilab.modules.xcos.palette.PaletteManager;
import org.scilab.modules.xcos.palette.view.PaletteManagerView;
import org.scilab.modules.xcos.preferences.XcosConfiguration;
-import org.scilab.modules.xcos.utils.BlockPositioning;
import org.scilab.modules.xcos.utils.FileUtils;
import org.scilab.modules.xcos.utils.XcosMessages;
/*
* Instance data
*/
- private final Map<File, Collection<XcosDiagram>> diagrams;
+ private final Map<Long, Collection<XcosDiagram>> diagrams;
private BrowserView browser;
private boolean onDiagramIteration = false;
private String lastError = null;
/*
* Allocate data
*/
- diagrams = new HashMap<File, Collection<XcosDiagram>>();
- // null is used for not saved diagrams
- addDiagram(null, null);
+ diagrams = new HashMap<Long, Collection<XcosDiagram>>();
// allocate and install the view on demand to avoid any cost
browser = null;
*/
public List<XcosDiagram> openedDiagrams() {
final List<XcosDiagram> opened = new ArrayList<XcosDiagram>();
- for (File f : diagrams.keySet()) {
- opened.addAll(openedDiagrams(f));
+ for (Long l : diagrams.keySet()) {
+ opened.addAll(openedDiagrams(l));
}
return opened;
* the file
* @return the opened diagrams list
*/
- public List<XcosDiagram> openedDiagrams(File f) {
+ public List<XcosDiagram> openedDiagrams(Long l) {
final List<XcosDiagram> opened = new ArrayList<XcosDiagram>();
- for (XcosDiagram d : diagrams.get(f)) {
+ for (XcosDiagram d : diagrams.get(l)) {
if (d.isOpened()) {
opened.add(d);
}
* the file
* @return is modified
*/
- public boolean isModified(File f) {
- for (XcosDiagram d : diagrams.get(f)) {
+ public boolean isModified(Long l) {
+ for (XcosDiagram d : diagrams.get(l)) {
if (d.isModified()) {
return true;
}
}
/**
+ * Popup a dialog to ask for a file creation
+ *
+ * @param f
+ * the file to create
+ * @return true if creation is has been performed
+ */
+ public boolean askForFileCreation(final XcosDiagram diag, final File f) {
+ AnswerOption answer;
+ try {
+ answer = ScilabModalDialog.show(diag.getAsComponent(), new String[] { String.format(XcosMessages.FILE_DOESNT_EXIST, f.getCanonicalFile()) },
+ XcosMessages.XCOS, IconType.QUESTION_ICON, ButtonType.YES_NO);
+ } catch (final IOException e) {
+ LOG.severe(e.toString());
+ answer = AnswerOption.YES_OPTION;
+ }
+
+ if (answer == AnswerOption.YES_OPTION) {
+ return diag.saveDiagramAs(f);
+ }
+
+ return false;
+ }
+
+ /**
* @return the global shared styleSheet
*/
public mxStylesheet getStyleSheet() {
*
* @param file
* the file to open. If null an empty diagram is created.
- * @param variable
- * the variable to decode. If null no decode is performed.
+ * @param diagramId
+ * the MVC ID to track. If 0 no association is performed.
*/
- public void open(final String file, final String variable) {
+ public void open(final String file, final long diagramId) {
if (!SwingUtilities.isEventDispatchThread()) {
LOG.severe(CALLED_OUTSIDE_THE_EDT_THREAD);
}
/*
* If it is the first window opened, then open the palette first.
*/
- if (file == null && variable == null && openedDiagrams().isEmpty()) {
+ if (file == null && diagramId == 0 && openedDiagrams().isEmpty()) {
PaletteManager.setVisible(true);
}
+ JavaController controller = new JavaController();
XcosDiagram diag = null;
final File f;
if (file != null) {
}
}
+ final long currentId;
+ if (diagramId != 0) {
+ currentId = diagramId;
+ } else {
+ currentId = controller.createObject(Kind.DIAGRAM);
+ }
+
if (diag != null) {
// loading disabled, unlock
synchronized (this) {
/*
* Allocate and setup a new diagram
*/
- diag = new XcosDiagram();
+ diag = new XcosDiagram(currentId, Kind.DIAGRAM);
diag.installListeners();
/*
* Ask for file creation
*/
if (f != null && !f.exists()) {
- if (!diag.askForFileCreation(f)) {
+ if (!askForFileCreation(diag, f)) {
// loading disabled, unlock
synchronized (this) {
setLastError("");
}
// return now, to avoid tab creation
+ controller.deleteObject(diag.getUId());
return;
}
}
/*
* Load the file
*/
- diag.transformAndLoadFile(file, variable);
+ diag.transformAndLoadFile(controller, file);
if (diag != null) {
- addDiagram(diag.getSavedFile(), diag);
+ addDiagram(diag.getUId(), diag);
}
}
public BrowserView getBrowser() {
if (browser == null) {
browser = new BrowserView();
- JavaController.register_view(BrowserView.class.getName(), browser);
+ JavaController.register_view(BrowserView.class.getSimpleName(), browser);
}
return browser;
}
}
/**
- * Get an unmodifiable view of the diagrams for a specific file
+ * Get an unmodifiable view of the diagrams for an UID
*
- * @param f
- * the file
+ * @param l
+ * the root diagram UID
* @return the diagram collection
*/
- public Collection<XcosDiagram> getDiagrams(final File f) {
- final Collection<XcosDiagram> diags = diagrams.get(f);
+ public Collection<XcosDiagram> getDiagrams(final long l) {
+ final Collection<XcosDiagram> diags = diagrams.get(l);
if (diags == null) {
return null;
}
* @param diag
* the diag
*/
- public void addDiagram(final File f, final XcosDiagram diag) {
+ public void addDiagram(final long l, final XcosDiagram diag) {
if (onDiagramIteration) {
throw new RuntimeException();
}
/*
* Create the collection if it does not exist
*/
- Collection<XcosDiagram> diags = diagrams.get(f);
+ Collection<XcosDiagram> diags = diagrams.get(l);
if (diags == null) {
diags = createDiagramCollection();
- diagrams.put(f, diags);
- }
-
- if (diag != null) {
- /*
- * Remove the diagram (and any child)
- */
- final Collection<XcosDiagram> toBeMoved = removeChildren(diag);
-
- /*
- * Add the diagram to the collection
- */
- diags.addAll(toBeMoved);
- }
- }
-
- private Collection<XcosDiagram> removeChildren(XcosDiagram diag) {
- final Collection<XcosDiagram> removed = new HashSet<XcosDiagram>();
- removed.add(diag);
-
- for (Collection<XcosDiagram> it : diagrams.values()) {
- if (!it.contains(diag)) {
- continue;
- }
-
- /*
- * Add all children to the removed collection.
- */
- for (XcosDiagram graph : it) {
- if (graph instanceof SuperBlockDiagram) {
- final XcosDiagram parent = ((SuperBlockDiagram) graph).getContainer().getParentDiagram();
-
- // As "it" is sorted according to the hierarchy, "removed"
- // is also ordered.
- if (removed.contains(parent)) {
- removed.add(graph);
- }
- }
-
- }
-
- /*
- * really remove them all
- */
- it.removeAll(removed);
-
+ diagrams.put(l, diags);
}
-
- return removed;
}
/**
*/
public boolean canClose(final XcosDiagram graph) {
boolean canClose = false;
- final File f = graph.getSavedFile();
- final boolean wasLastOpened = openedDiagrams(f).size() <= 1;
- final boolean isModified = isModified(f);
+ JavaController controller = new JavaController();
+ long[] rootDiagram = new long[1];
+ controller.getObjectProperty(graph.getUId(), graph.getKind(), ObjectProperties.PARENT_DIAGRAM, rootDiagram);
+ if (rootDiagram[0] == 0l) {
+ rootDiagram[0] = graph.getUId();
+ }
+
+ final boolean wasLastOpened = openedDiagrams(rootDiagram[0]).size() <= 1;
+ final boolean isModified = isModified(rootDiagram[0]);
if (!(wasLastOpened && isModified)) {
canClose = true;
}
switch (ans) {
case YES_OPTION:
- canClose = diagrams.get(f).iterator().next().saveDiagram();
+ canClose = diagrams.get(rootDiagram[0]).iterator().next().saveDiagram();
break;
case NO_OPTION:
canClose = true; // can close
* the diagram to close
*/
public void destroy(XcosDiagram graph) {
- final File f = graph.getSavedFile();
- final boolean wasLastOpenedForFile = openedDiagrams(f).size() <= 1;
+ JavaController controller = new JavaController();
+ long[] rootDiagram = new long[1];
+ controller.getObjectProperty(graph.getUId(), graph.getKind(), ObjectProperties.PARENT_DIAGRAM, rootDiagram);
+ if (rootDiagram[0] == 0l) {
+ rootDiagram[0] = graph.getUId();
+ }
- if (!onDiagramIteration && wasLastOpenedForFile) {
- diagrams.remove(f);
+ final boolean wasLastOpenedForFile = openedDiagrams(rootDiagram[0]).size() <= 1;
+ if (wasLastOpenedForFile) {
+ diagrams.remove(rootDiagram[0]);
}
if (openedDiagrams().size() <= 0) {
if (status) {
/* reset the shared instance state */
instance.diagrams.keySet().clear();
- instance.addDiagram(null, null);
/* terminate any remaining simulation */
InterpreterManagement.putCommandInScilabQueue("if isdef('haltscicos'), haltscicos(), end;");
*
* @param file
* The filename (can be null)
- * @param variable
- * The Scilab variable to load (can be null)
+ * @param diagramId
+ * The Xcos DIAGRAM model ID (can be null)
*/
@ScilabExported(module = "xcos", filename = "Xcos.giws.xml")
- public static void xcos(final String file, final String variable) {
+ public static void xcos(final String file, final long diagramId) {
final Xcos instance = getInstance();
instance.lastError = null;
@Override
public void run() {
// open on EDT
- instance.open(file, variable);
+ instance.open(file, diagramId);
}
});
-
- /*
- * Wait loading and fail on error only if the variable is readeable
- */
- try {
- while (variable != null && instance.lastError == null) {
- instance.wait();
- }
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
}
if (instance.lastError != null && !instance.lastError.isEmpty()) {
throw new RuntimeException(instance.lastError);
* The message to display.
*/
@ScilabExported(module = "xcos", filename = "Xcos.giws.xml")
- public static void warnCellByUID(final String[] uid, final String message) {
+ public static void warnCellByUID(final String[] uids, final String message) {
try {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
- getInstance().warnCell(uid, message);
+ getInstance().warnCell(uids, message);
}
});
} catch (final InterruptedException e) {
}
}
- private void warnCell(final String[] uid, final String message) {
- final mxCell cell = (mxCell) lookupForCell(uid);
-
- // We are unable to find the block with the right id
- if (cell == null) {
- return;
- }
-
- // finally perform the action on the last block
- final XcosDiagram parent = findParent(cell);
- parent.warnCellByUID(cell.getId(), message);
-
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- /*
- * Focus on an existing diagram
- */
- XcosTab.get(parent).setCurrent();
- }
- });
- }
-
- public Object lookupForCell(final String[] uid) {
- final ArrayDeque<String> deque = new ArrayDeque<String>(Arrays.asList(uid));
-
- // specific case with an empty array
- if (deque.isEmpty()) {
- return null;
- }
-
- // first element
- Object cell = null;
- Collection<XcosDiagram> diags = null;
- String id = deque.pop();
- try {
- onDiagramIteration = true;
-
- for (Collection<XcosDiagram> ds : diagrams.values()) {
- if (ds.isEmpty()) {
- continue;
- }
-
- final XcosDiagram root = ds.iterator().next();
-
- cell = ((mxGraphModel) root.getModel()).getCell(id);
- if (cell != null) {
- diags = ds;
- break;
- }
- }
- } finally {
- onDiagramIteration = false;
- }
-
- // loop to get only the last diagram
- while (cell instanceof SuperBlock && !deque.isEmpty()) {
- final SuperBlock block = (SuperBlock) cell;
+ private void warnCell(final String[] uids, final String message) {
- block.getParentDiagram().warnCellByUID(block.getId(), XcosMessages.ERROR_UNABLE_TO_COMPILE_THIS_SUPER_BLOCK);
+ final mxCell[] cells = lookupForCells(uids);
+ for (int i = cells.length - 1; i >= 0; --i) {
+ mxCell cell = cells[i];
- id = deque.pop();
+ // perform the action on the last visible block
+ if (cell != null) {
+ final XcosDiagram parent = findParent(cell);
+ parent.warnCellByUID(cell.getId(), message);
- if (!diags.contains(block.getChild()) || !block.getChild().isOpened()) {
- block.openBlockSettings(null);
- }
-
- final mxGraphModel model = ((mxGraphModel) block.getChild().getModel());
- cell = model.getCell(id);
- }
-
- return cell;
- }
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ /*
+ * Focus on an existing diagram
+ */
+ XcosTab.get(parent).setCurrent();
+ }
+ });
- @ScilabExported(module = "xcos", filename = "Xcos.giws.xml")
- public static void updateBlock(final String h5File) {
- try {
- SwingUtilities.invokeAndWait(new Runnable() {
- @Override
- public void run() {
- getInstance().updateBlockInstance();
- }
- });
- } catch (final InterruptedException e) {
- LOG.severe(e.toString());
- } catch (final InvocationTargetException e) {
- Throwable throwable = e;
- String firstMessage = null;
- while (throwable != null) {
- firstMessage = throwable.getLocalizedMessage();
- throwable = throwable.getCause();
+ return;
}
- throw new RuntimeException(firstMessage, e);
- }
- }
-
- private void updateBlockInstance() {
- // get the cell
- BasicBlock modifiedBlock;
-
- final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
- if (handler == null) {
- return;
- }
-
- try {
- modifiedBlock = handler.readBlock();
- } catch (ScicosFormatException e) {
- throw new RuntimeException(e);
- } finally {
- handler.release();
- }
- if (modifiedBlock == null) {
- return;
- }
- // diagram lookup
- final XcosDiagram diag = findParent(modifiedBlock);
- if (diag == null) {
- throw new RuntimeException(Messages.gettext("parent diagram not found."));
}
-
- // finally update the instance
- final mxGraphModel model = (mxGraphModel) diag.getModel();
- final BasicBlock block = (BasicBlock) model.getCell(modifiedBlock.getId());
- assert block != null;
-
- block.updateBlockSettings(modifiedBlock);
- block.setInterfaceFunctionName(modifiedBlock.getInterfaceFunctionName());
- block.setSimulationFunctionName(modifiedBlock.getSimulationFunctionName());
- block.setSimulationFunctionType(modifiedBlock.getSimulationFunctionType());
- if (block instanceof SuperBlock) {
- ((SuperBlock) block).setChild(null);
- }
-
- block.setStyle(block.getStyle() + ";blockWithLabel");
- block.setValue(block.getSimulationFunctionName());
- BlockPositioning.updateBlockView(block);
}
- /**
- * This function convert a Xcos diagram to Scilab variable.
- *
- * This method invoke Xcos operation on the EDT thread.
- *
- * @param xcosFile
- * The xcos diagram file
- * @return Not used (compatibility)
- */
- @ScilabExported(module = "xcos", filename = "Xcos.giws.xml")
- public static int xcosDiagramToScilab(final String xcosFile) {
- final File file = new File(xcosFile);
+ public mxCell[] lookupForCells(final String[] uid) {
+ mxCell[] found = new mxCell[uid.length];
+ XcosView view = (XcosView) JavaController.lookup_view(Xcos.class.getSimpleName());
- if (!file.exists()) {
- return 1;
- }
+ final String[] sortedUIDs = Arrays.copyOf(uid, uid.length);
+ Arrays.sort(sortedUIDs);
- try {
- SwingUtilities.invokeAndWait(new Runnable() {
- @Override
- public void run() {
- LOG.finest("xcosDiagramToScilab: entering");
- final XcosDiagram diagram = new XcosDiagram();
-
- final XcosFileType filetype = XcosFileType.findFileType(file);
- if (filetype != null) {
- try {
- LOG.finest("xcosDiagramToScilab: initialized");
- filetype.load(xcosFile, diagram);
- LOG.finest("xcosDiagramToScilab: loaded");
-
- final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
- if (handler == null) {
- return;
- }
-
- try {
- handler.writeDiagram(diagram);
- } finally {
- handler.release();
- }
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- LOG.finest("xcosDiagramToScilab: exiting");
- }
- });
- } catch (final InterruptedException e) {
- throw new RuntimeException(e);
- } catch (final InvocationTargetException e) {
- Throwable throwable = e;
- String firstMessage = null;
- while (throwable != null) {
- firstMessage = throwable.getLocalizedMessage();
- throwable = throwable.getCause();
- }
+ view.getVisibleObjects().values().stream()
+ //look for the visible objects in the UID set
+ .filter(o -> o instanceof mxCell)
+ .map(o -> (mxCell) o)
+ .filter(o -> Arrays.binarySearch(sortedUIDs, o.getId()) >= 0)
- throw new RuntimeException(firstMessage, e);
- }
+ // push the results to the resulting array
+ .forEach(o -> found[Arrays.asList(uid).indexOf(o.getId())] = o);
- return 0;
+ return found;
}
/**
}
/**
- * Open a diagram by uid.
- *
- * This method invoke Xcos operation on the EDT thread.
- *
- * @param uid
- * UID path to a block.
- */
- @ScilabExported(module = "xcos", filename = "Xcos.giws.xml")
- @Deprecated
- public static void xcosDiagramOpen(final String[] uid) {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Close a diagram by uid.
- *
- * This method invoke Xcos operation on the EDT thread.
- *
- * @param uid
- * The diagram id path
- */
- @ScilabExported(module = "xcos", filename = "Xcos.giws.xml")
- @Deprecated
- public static void xcosDiagramClose(final String[] uid) {
- throw new UnsupportedOperationException();
- }
-
- /**
* Inform Xcos the simulator has just started
*
*/
*/
public static XcosDiagram findParent(Object cell) {
final Xcos instance = getInstance();
- try {
- instance.onDiagramIteration = true;
- for (Collection<XcosDiagram> diags : instance.diagrams.values()) {
- for (XcosDiagram diag : diags) {
- final mxGraphModel model = (mxGraphModel) diag.getModel();
+ for (Collection<XcosDiagram> diags : instance.diagrams.values()) {
+ for (XcosDiagram diag : diags) {
+ final mxGraphModel model = (mxGraphModel) diag.getModel();
- // use the O(1) lookup
- if (cell instanceof mxICell && model.getCell(((mxICell) cell).getId()) != null) {
- if (cell instanceof BasicBlock) {
- ((BasicBlock) cell).setParentDiagram(diag);
- }
- return diag;
- }
+ // use the O(1) lookup
+ if (cell instanceof mxICell && model.getCell(((mxICell) cell).getId()) != null) {
+ return diag;
}
}
- } finally {
- instance.onDiagramIteration = false;
}
return null;
final XcosTab tab = new XcosTab(graph, uuid);
ScilabTabFactory.getInstance().addToCache(tab);
- Xcos.getInstance().addDiagram(graph.getSavedFile(), graph);
+ Xcos.getInstance().addDiagram(graph.getUId(), graph);
graph.setOpened(true);
if (visible) {
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2015 - Scilab Enterprises - Clement DAVID
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ *
+ */
+package org.scilab.modules.xcos;
+
+import java.util.ArrayList;
+import java.util.EnumMap;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.swing.SwingUtilities;
+
+/**
+ * Generic view to dispatch common GUI update to the right JGraphX component
+ */
+public class XcosView extends View {
+
+ private final static class Entry {
+ XcosViewListener listener;
+ boolean onCallerThread;
+ EnumSet<ObjectProperties> listenedProperties;
+
+ public Entry(final boolean onCallerThread, final EnumSet<ObjectProperties> properties, final XcosViewListener listener) {
+ this.listener = listener;
+ this.onCallerThread = onCallerThread;
+ this.listenedProperties = properties;
+ }
+ }
+
+ private final EnumMap<Kind, ArrayList<Entry>> registeredListeners;
+ private final HashMap<Long, Object> visibleObjects;
+
+ /**
+ * Default constructor
+ */
+ public XcosView() {
+ registeredListeners = new EnumMap<>(Kind.class);
+ visibleObjects = new HashMap<Long, Object>();
+ }
+
+ /**
+ * @return all visible Java objects
+ */
+ public HashMap<Long, Object> getVisibleObjects() {
+ return visibleObjects;
+ }
+
+ /*
+ * Implement the MVC View interface by dispatch-ing to the listeners
+ */
+
+ @Override
+ public final void objectCreated(long uid, Kind kind) {
+ List<Entry> listeners = registeredListeners.get(kind);
+ if (listeners == null) {
+ return;
+ }
+
+ for (Entry e : listeners) {
+ if (e.onCallerThread) {
+ e.listener.objectCreated(uid, kind);
+ } else {
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ e.listener.objectCreated(uid, kind);
+ }
+ });
+ }
+ }
+ }
+
+ @Override
+ public final void objectReferenced(long uid, Kind kind) {
+ List<Entry> listeners = registeredListeners.get(kind);
+ if (listeners == null) {
+ return;
+ }
+
+ for (Entry e : listeners) {
+ if (e.onCallerThread) {
+ e.listener.objectReferenced(uid, kind);
+ } else {
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ e.listener.objectReferenced(uid, kind);
+ }
+ });
+ }
+ }
+ }
+
+ @Override
+ public final void objectUnreferenced(long uid, Kind kind) {
+ List<Entry> listeners = registeredListeners.get(kind);
+ if (listeners == null) {
+ return;
+ }
+
+ for (Entry e : listeners) {
+ if (e.onCallerThread) {
+ e.listener.objectUnreferenced(uid, kind);
+ } else {
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ e.listener.objectUnreferenced(uid, kind);
+ }
+ });
+ }
+ }
+ }
+
+ @Override
+ public final void objectDeleted(long uid, Kind kind) {
+ List<Entry> listeners = registeredListeners.get(kind);
+ if (listeners == null) {
+ return;
+ }
+
+ for (Entry e : listeners) {
+ if (e.onCallerThread) {
+ e.listener.objectDeleted(uid, kind);
+ } else {
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ e.listener.objectDeleted(uid, kind);
+ }
+ });
+ }
+ }
+ }
+
+ @Override
+ public final void propertyUpdated(long uid, Kind kind, ObjectProperties property, UpdateStatus status) {
+ List<Entry> listeners = registeredListeners.get(kind);
+ if (listeners == null) {
+ return;
+ }
+
+ for (Entry e : listeners) {
+ if (e.onCallerThread) {
+ if (e.listenedProperties.contains(property)) {
+ e.listener.propertyUpdated(uid, kind, property, status);
+ }
+ } else {
+ if (e.listenedProperties.contains(property)) {
+ SwingUtilities.invokeLater(new Runnable() {
+ @Override
+ public void run() {
+ e.listener.propertyUpdated(uid, kind, property, status);
+ }
+ });
+ }
+ }
+ }
+ }
+
+ /*
+ * Helpers to manage the listeners on the EDT
+ */
+
+ public void addXcosViewListener(final XcosViewListener listener) {
+ for (Kind kind : EnumSet.allOf(Kind.class)) {
+ ArrayList<Entry> l = registeredListeners.get(kind);
+ if (l == null) {
+ l = new ArrayList<>();
+ registeredListeners.put(kind, l);
+ }
+
+ l.add(new Entry(false, EnumSet.allOf(ObjectProperties.class), listener));
+ }
+ }
+
+ public void addXcosViewListener(final Kind kind, final XcosViewListener listener) {
+ ArrayList<Entry> l = registeredListeners.get(kind);
+ if (l == null) {
+ l = new ArrayList<>();
+ registeredListeners.put(kind, l);
+ }
+
+ l.add(new Entry(false, EnumSet.allOf(ObjectProperties.class), listener));
+ }
+
+ public void addXcosViewListener(final Kind kind, final ObjectProperties property, final XcosViewListener listener) {
+ ArrayList<Entry> l = registeredListeners.get(kind);
+ if (l == null) {
+ l = new ArrayList<>();
+ registeredListeners.put(kind, l);
+ }
+
+ l.add(new Entry(false, EnumSet.of(property), listener));
+ }
+
+ public void addXcosViewListener(final Kind kind, boolean onCallerThread, final EnumSet<ObjectProperties> properties, final XcosViewListener listener) {
+ ArrayList<Entry> l = registeredListeners.get(kind);
+ if (l == null) {
+ l = new ArrayList<>();
+ registeredListeners.put(kind, l);
+ }
+
+ l.add(new Entry(onCallerThread, properties, listener));
+ }
+}
--- /dev/null
+/*
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2015 - Scilab Enterprises - Clement DAVID
+ *
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at
+ * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
+ *
+ */
+package org.scilab.modules.xcos;
+
+/**
+ * Dummy abstract implementation of an XcosView listener.
+ */
+public abstract class XcosViewListener {
+ public void objectCreated(long uid, Kind kind) {};
+ public void objectDeleted(long uid, Kind kind) {};
+ public void objectReferenced(long uid, Kind kind) {};
+ public void objectUnreferenced(long uid, Kind kind) {};
+ public void propertyUpdated(long uid, Kind kind, ObjectProperties property, UpdateStatus status) {};
+}
package org.scilab.modules.xcos.actions;
import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.util.logging.Logger;
-import javax.swing.SwingWorker;
-
-import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement;
-import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.InterpreterException;
import org.scilab.modules.graph.ScilabComponent;
import org.scilab.modules.graph.ScilabGraph;
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.xcos.graph.XcosDiagram;
-import org.scilab.modules.xcos.io.scicos.ScilabDirectHandler;
import org.scilab.modules.xcos.utils.XcosMessages;
/**
graph.info(XcosMessages.EXPORT_IN_PROGRESS);
- final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
- if (handler == null) {
- return;
- }
- (new SwingWorker<Void, Void>() {
-
- @Override
- protected Void doInBackground() {
- try {
- handler.writeDiagram(((XcosDiagram) getGraph(null)));
- ((XcosDiagram) getGraph(null)).setReadOnly(true);
- } catch (Exception e) {
- cancel(true);
- }
- return null;
- }
-
- @Override
- protected void done() {
- if (isCancelled()) {
- graph.info(XcosMessages.EMPTY_INFO);
-
- handler.release();
- return;
- }
-
- graph.info(XcosMessages.COMPILATION_IN_PROGRESS);
- String cmd = "cpr = xcos_compile(scs_m);";
-
- final ActionListener action = new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- graph.setReadOnly(false);
- graph.info(XcosMessages.EMPTY_INFO);
-
- handler.release();
- }
- };
-
- try {
- ScilabInterpreterManagement.asynchronousScilabExec(action, cmd);
- } catch (InterpreterException e) {
- Logger.getLogger(CompileAction.class.getName()).severe(e.toString());
-
- handler.release();
- }
- }
-
- }).execute();
+ // FIXME: implement the compilation
+ // final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
+ // if (handler == null) {
+ // return;
+ // }
+ // (new SwingWorker<Void, Void>() {
+ //
+ // @Override
+ // protected Void doInBackground() {
+ // try {
+ // handler.writeDiagram(((XcosDiagram) getGraph(null)));
+ // ((XcosDiagram) getGraph(null)).setReadOnly(true);
+ // } catch (Exception e) {
+ // cancel(true);
+ // }
+ // return null;
+ // }
+ //
+ // @Override
+ // protected void done() {
+ // if (isCancelled()) {
+ // graph.info(XcosMessages.EMPTY_INFO);
+ //
+ // handler.release();
+ // return;
+ // }
+ //
+ // graph.info(XcosMessages.COMPILATION_IN_PROGRESS);
+ // String cmd = "cpr = xcos_compile(scs_m);";
+ //
+ // final ActionListener action = new ActionListener() {
+ // @Override
+ // public void actionPerformed(ActionEvent e) {
+ // graph.setReadOnly(false);
+ // graph.info(XcosMessages.EMPTY_INFO);
+ //
+ // handler.release();
+ // }
+ // };
+ //
+ // try {
+ // ScilabInterpreterManagement.asynchronousScilabExec(action, cmd);
+ // } catch (InterpreterException e) {
+ // Logger.getLogger(CompileAction.class.getName()).severe(e.toString());
+ //
+ // handler.release();
+ // }
+ // }
+ //
+ // }).execute();
}
}
+++ /dev/null
-/*
- * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
- * Copyright (C) 2009 - DIGITEO - Bruno JOFRET
- * Copyright (C) 2009 - DIGITEO - Vincent COUVERT
- * Copyright (C) 2010 - DIGITEO - Clement DAVID
- *
- * This file must be used under the terms of the CeCILL.
- * This source file is licensed as described in the file COPYING, which
- * you should have received as part of this distribution. The terms
- * are also available at
- * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
- *
- */
-
-package org.scilab.modules.xcos.actions;
-
-import java.awt.event.ActionEvent;
-
-import javax.swing.JButton;
-
-import org.scilab.modules.graph.ScilabComponent;
-import org.scilab.modules.graph.ScilabGraph;
-import org.scilab.modules.graph.actions.base.DefaultAction;
-import org.scilab.modules.gui.menuitem.MenuItem;
-import org.scilab.modules.xcos.graph.XcosDiagram;
-import org.scilab.modules.xcos.io.scicos.ScilabDirectHandler;
-import org.scilab.modules.xcos.utils.XcosMessages;
-
-/**
- * Dump the graph into scilab.
- *
- * This action is only used for debugging purpose but not on any release
- * version.
- */
-@SuppressWarnings(value = { "serial" })
-public final class DumpAction extends DefaultAction {
- /** Name of the action */
- public static final String NAME = XcosMessages.DUMP;
- /** Icon name of the action */
- public static final String SMALL_ICON = "";
- /** Mnemonic key of the action */
- public static final int MNEMONIC_KEY = 0;
- /** Accelerator key for the action */
- public static final int ACCELERATOR_KEY = 0;
-
- /**
- * @param scilabGraph
- * graph
- */
- public DumpAction(ScilabGraph scilabGraph) {
- super(scilabGraph);
- }
-
- /**
- * @param scilabGraph
- * graph
- * @return push button
- */
- public static JButton dumpButton(ScilabGraph scilabGraph) {
- return createButton(scilabGraph, DumpAction.class);
- }
-
- /**
- * @param scilabGraph
- * graph
- * @return menu item
- */
- public static MenuItem dumpMenu(ScilabGraph scilabGraph) {
- return createMenu(scilabGraph, DumpAction.class);
- }
-
- /**
- * Do action !!!
- *
- * @param e
- * params
- * @see org.scilab.modules.gui.events.callback.CallBack#actionPerformed(java.awt.event.ActionEvent)
- */
- @Override
- public void actionPerformed(ActionEvent e) {
- final XcosDiagram graph = (XcosDiagram) getGraph(e);
-
- // action disabled when the cell is edited
- final ScilabComponent comp = ((ScilabComponent) graph.getAsComponent());
- if (comp.isEditing()) {
- return;
- }
-
- final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
- if (handler == null) {
- return;
- }
- try {
- handler.writeDiagram(graph);
- } finally {
- handler.release();
- }
- }
-}
import org.scilab.modules.graph.utils.StyleMap;
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.gui.utils.ScilabSwingUtilities;
-import org.scilab.modules.xcos.block.BasicBlock;
import org.scilab.modules.xcos.block.SuperBlock;
import org.scilab.modules.xcos.block.TextBlock;
import org.scilab.modules.xcos.graph.XcosDiagram;
final mxGraphModel model = (mxGraphModel) graph.getModel();
final mxCell cell = dialog.getCell();
- final StyleMap cellStyle = new StyleMap("");
- if (cell instanceof BasicBlock) {
- cellStyle.put(((BasicBlock) cell).getInterfaceFunctionName(), null);
- }
- cellStyle.putAll(cell.getStyle());
+ final StyleMap cellStyle = new StyleMap(cell.getStyle());
final mxCell identifier;
final StyleMap identifierStyle;
}
cellStyle.clear();
- if (cell instanceof BasicBlock) {
- cellStyle.put(((BasicBlock) cell).getInterfaceFunctionName(), null);
- }
dialog.setValues(DEFAULT_BORDERCOLOR, DEFAULT_FILLCOLOR, mxConstants.DEFAULT_FONTFAMILY, mxConstants.DEFAULT_FONTSIZE, 0, DEFAULT_BORDERCOLOR, "", null);
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.ListIterator;
import java.util.Set;
import java.util.TreeSet;
import org.scilab.modules.gui.messagebox.ScilabModalDialog.AnswerOption;
import org.scilab.modules.gui.messagebox.ScilabModalDialog.ButtonType;
import org.scilab.modules.gui.messagebox.ScilabModalDialog.IconType;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.Kind;
+import org.scilab.modules.xcos.ObjectProperties;
+import org.scilab.modules.xcos.VectorOfScicosID;
+import org.scilab.modules.xcos.Xcos;
import org.scilab.modules.xcos.XcosTab;
-import org.scilab.modules.xcos.block.SuperBlock;
import org.scilab.modules.xcos.configuration.ConfigurationManager;
-import org.scilab.modules.xcos.graph.SuperBlockDiagram;
import org.scilab.modules.xcos.graph.XcosDiagram;
import org.scilab.modules.xcos.utils.XcosMessages;
import org.w3c.dom.Document;
-import com.mxgraph.model.mxCell;
-import com.mxgraph.model.mxGraphModel;
-import com.mxgraph.model.mxGraphModel.Filter;
import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.util.mxCellRenderer;
import com.mxgraph.util.mxUtils;
*/
@Override
public void actionPerformed(ActionEvent e) {
-
- final XcosDiagram graph = (XcosDiagram) getGraph(null);
+ final XcosDiagram graph = ((XcosDiagram) getGraph(null)).getRootDiagram();
// Adds a filter for each supported image format
- Collection<String> imageFormats = Arrays.asList(ImageIO
- .getWriterFileSuffixes());
+ Collection<String> imageFormats = Arrays.asList(ImageIO.getWriterFileSuffixes());
// The mask ordered collection
Set<String> mask = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
ConfigurationManager.configureCurrentDirectory(fc);
- int selection = fc.showSaveDialog(graph.getAsComponent());
+ int selection = fc.showSaveDialog(getGraph(null).getAsComponent());
if (selection == JFileChooser.APPROVE_OPTION) {
File dir = fc.getSelectedFile();
/* update states from the format */
if ((!format.equalsIgnoreCase("png"))
- || ScilabModalDialog.show(XcosTab.get(graph),
+ || ScilabModalDialog.show(XcosTab.get((XcosDiagram) getGraph(null)),
XcosMessages.TRANSPARENT_BACKGROUND, XcosMessages.XCOS,
IconType.QUESTION_ICON, ButtonType.YES_NO) != AnswerOption.YES_OPTION) {
useBackground = true;
}
- final Filter superBlockFilter = new Filter() {
- @Override
- public boolean filter(Object cell) {
- if (cell instanceof SuperBlock) {
- final SuperBlock blk = (SuperBlock) cell;
- blk.createChildDiagram();
- return true;
- }
- return false;
- }
- };
-
- /*
- * Append all the superblocks
- */
- final ArrayList<Object> superBlocks = new ArrayList<Object>();
- final ArrayList<String> filenameDescriptors = new ArrayList<String>();
- Collection<Object> filtered = mxGraphModel.filterDescendants(graph.getModel(), superBlockFilter);
- superBlocks.addAll(filtered);
-
- fillFilenameDescriptors(graph.getTitle(), graph, filenameDescriptors, filtered);
-
/*
- * Iterate recursively on children
+ * Instantiate all the sub-diagrams
*/
- for (int i = 0; i < superBlocks.size(); i++) {
- final SuperBlock blk = (SuperBlock) superBlocks.get(i);
- final SuperBlockDiagram diag = blk.getChild();
-
- filtered = mxGraphModel.filterDescendants(diag.getModel(), superBlockFilter);
- superBlocks.addAll(filtered);
-
- fillFilenameDescriptors(graph.getTitle(), graph, filenameDescriptors, filtered);
+ JavaController controller = new JavaController();
+ ArrayList<XcosDiagram> diagrams = new ArrayList<>();
+ diagrams.add(graph);
+
+ // append the already allocated diagram
+ diagrams.addAll(Xcos.getInstance().getDiagrams(graph.getUId()));
+
+ ArrayList<Long> stash = new ArrayList<>();
+ allocateDiagrams(controller, diagrams, stash, graph.getUId(), Kind.DIAGRAM);
+ while (!stash.isEmpty()) {
+ final long uid = stash.remove(stash.size() - 1);
+ allocateDiagrams(controller, diagrams, stash, uid, Kind.BLOCK);
}
/*
try {
export(graph, new File(dir, graph.getTitle() + "." + format), format);
- for (int i = 0; i < superBlocks.size(); i++) {
- export(((SuperBlock)superBlocks.get(i)).getChild(), new File(dir, filenameDescriptors.get(i) + "." + format), format);
+ for (XcosDiagram d : diagrams) {
+ export(d, new File(dir, d.getTitle() + "." + format), format);
}
} catch (IOException e1) {
e1.printStackTrace();
}
}
- private void fillFilenameDescriptors(final String rootName, final XcosDiagram graph, final ArrayList<String> filenameDescriptors, final Collection<Object> filtered) {
- filenameDescriptors.ensureCapacity(filenameDescriptors.size() + filtered.size());
+ private void allocateDiagrams(JavaController controller, ArrayList<XcosDiagram> diagrams, ArrayList<Long> stash,
+ final long uid, final Kind kind) {
+ final VectorOfScicosID children = new VectorOfScicosID();
+ controller.getObjectProperty(uid, kind, ObjectProperties.CHILDREN, children);
+
+ final int len = (int) children.size();
+ for (int i = 0; i < len ; i++) {
+ String[] interfaceFunction = new String[1];
+ long currentUID = children.get(i);
+ if (controller.getKind(currentUID) == Kind.BLOCK) {
+ controller.getObjectProperty(children.get(i), Kind.BLOCK, ObjectProperties.INTERFACE_FUNCTION, interfaceFunction);
+ if (!"SUPER_f".equals(interfaceFunction[0])) {
+ continue;
+ }
- ListIterator<String> it = filenameDescriptors.listIterator();
- for (Object object : filtered) {
- final SuperBlock blk = (SuperBlock) object;
- final mxCell identifierLabel = graph.getCellIdentifier(blk);
- final String identifier;
- if (identifierLabel != null) {
- identifier = identifierLabel.getValue().toString();
- } else {
- identifier = "";
+ if (diagrams.stream().noneMatch(d -> d.getUId() == currentUID)) {
+ final XcosDiagram child = new XcosDiagram(currentUID, Kind.BLOCK);
+ diagrams.add(child);
+ stash.add(currentUID);
+ }
}
-
- String filename = rootName;
- if (!identifier.isEmpty()) {
- filename += "_" + identifier;
- } else {
- filename += "_" + it.nextIndex();
- }
- it.add(filename);
}
}
package org.scilab.modules.xcos.actions;
import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
import java.util.logging.Logger;
import javax.swing.Action;
-import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement;
-import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.InterpreterException;
import org.scilab.modules.graph.ScilabGraph;
import org.scilab.modules.graph.actions.base.DefaultAction;
-import org.scilab.modules.xcos.block.BasicBlock;
import org.scilab.modules.xcos.graph.XcosDiagram;
-import org.scilab.modules.xcos.io.scicos.ScicosFormatException;
-import org.scilab.modules.xcos.io.scicos.ScilabDirectHandler;
-import org.scilab.modules.xcos.utils.XcosConstants;
-import org.scilab.modules.xcos.utils.XcosEvent;
-
-import com.mxgraph.util.mxEventObject;
/**
* External action
@Override
public void actionPerformed(ActionEvent e) {
- final XcosDiagram graph = (XcosDiagram) getGraph(e);
- final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
- if (handler == null) {
- return;
- }
-
- final BasicBlock block;
- final ActionListener callback;
- try {
- /*
- * Export the whole diagram, to update all the sub-diagrams on demand.
- */
- handler.writeDiagram(graph.getRootDiagram());
-
- /*
- * Then export the selected block
- */
- Object cell = graph.getSelectionCell();
- if (cell instanceof BasicBlock) {
- block = (BasicBlock) cell;
- handler.writeBlock(block);
- } else {
- block = null;
- }
-
- /*
- * Import the updated block
- */
- if (block != null) {
- callback = new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- try {
-
- final BasicBlock modifiedBlock = handler.readBlock();
- block.updateBlockSettings(modifiedBlock);
-
- graph.fireEvent(new mxEventObject(XcosEvent.ADD_PORTS, XcosConstants.EVENT_BLOCK_UPDATED, block));
- } catch (ScicosFormatException e1) {
- LOG.severe(e1.getMessage());
- } finally {
- handler.release();
- }
- }
- };
- } else {
- callback = new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- handler.release();
- }
- };
- }
-
- ScilabInterpreterManagement.asynchronousScilabExec(callback, localCommand);
- } catch (InterpreterException e2) {
- LOG.warning(e2.toString());
- handler.release();
- }
+ // FIXME: implement the external action
+ // final XcosDiagram graph = (XcosDiagram) getGraph(e);
+ // final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
+ // if (handler == null) {
+ // return;
+ // }
+ //
+ // final BasicBlock block;
+ // final ActionListener callback;
+ // try {
+ // /*
+ // * Export the whole diagram, to update all the sub-diagrams on demand.
+ // */
+ // handler.writeDiagram(graph.getRootDiagram());
+ //
+ // /*
+ // * Then export the selected block
+ // */
+ // Object cell = graph.getSelectionCell();
+ // if (cell instanceof BasicBlock) {
+ // block = (BasicBlock) cell;
+ // handler.writeBlock(block);
+ // } else {
+ // block = null;
+ // }
+ //
+ // /*
+ // * Import the updated block
+ // */
+ // if (block != null) {
+ // callback = new ActionListener() {
+ // @Override
+ // public void actionPerformed(ActionEvent e) {
+ // try {
+ //
+ // final BasicBlock modifiedBlock = handler.readBlock();
+ // block.updateBlockSettings(modifiedBlock);
+ //
+ // graph.fireEvent(new mxEventObject(XcosEvent.ADD_PORTS, XcosConstants.EVENT_BLOCK_UPDATED, block));
+ // } catch (ScicosFormatException e1) {
+ // LOG.severe(e1.getMessage());
+ // } finally {
+ // handler.release();
+ // }
+ // }
+ // };
+ // } else {
+ // callback = new ActionListener() {
+ // @Override
+ // public void actionPerformed(ActionEvent e) {
+ // handler.release();
+ // }
+ // };
+ // }
+ //
+ // ScilabInterpreterManagement.asynchronousScilabExec(callback, localCommand);
+ // } catch (InterpreterException e2) {
+ // LOG.warning(e2.toString());
+ //
+ // handler.release();
+ // }
}
}
*/
package org.scilab.modules.xcos.actions;
-import static org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.asynchronousScilabExec;
-import static org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.buildCall;
-
import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.util.logging.Logger;
import javax.swing.JButton;
-import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.InterpreterException;
-import org.scilab.modules.graph.ScilabComponent;
import org.scilab.modules.graph.ScilabGraph;
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.xcos.graph.XcosDiagram;
-import org.scilab.modules.xcos.io.scicos.ScilabDirectHandler;
import org.scilab.modules.xcos.utils.XcosMessages;
/**
public void actionPerformed(ActionEvent e) {
final XcosDiagram graph = (XcosDiagram) getGraph(e);
- // action disabled when the cell is edited
- final ScilabComponent comp = ((ScilabComponent) graph.getAsComponent());
- if (comp.isEditing()) {
- return;
- }
-
- final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
- if (handler == null) {
- return;
- }
-
- graph.info(XcosMessages.INITIALIZING_MODELICA_COMPILER);
-
- handler.writeDiagram(graph.getRootDiagram());
-
- final String cmd = buildCall("xcosConfigureModelica");
-
- final ActionListener action = new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- graph.info(XcosMessages.EMPTY_INFO);
- handler.release();
- }
- };
-
- try {
- asynchronousScilabExec(action, cmd);
- } catch (InterpreterException e1) {
- Logger.getLogger(InitModelicaAction.class.getName()).severe(e.toString());
- handler.release();
- }
+ // FIXME: implement the modelica init
+ // // action disabled when the cell is edited
+ // final ScilabComponent comp = ((ScilabComponent) graph.getAsComponent());
+ // if (comp.isEditing()) {
+ // return;
+ // }
+ //
+ // final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
+ // if (handler == null) {
+ // return;
+ // }
+ //
+ // graph.info(XcosMessages.INITIALIZING_MODELICA_COMPILER);
+ //
+ // handler.writeDiagram(graph.getRootDiagram());
+ //
+ // final String cmd = buildCall("xcosConfigureModelica");
+ //
+ // final ActionListener action = new ActionListener() {
+ // @Override
+ // public void actionPerformed(ActionEvent e) {
+ // graph.info(XcosMessages.EMPTY_INFO);
+ // handler.release();
+ // }
+ // };
+ //
+ // try {
+ // asynchronousScilabExec(action, cmd);
+ // } catch (InterpreterException e1) {
+ // Logger.getLogger(InitModelicaAction.class.getName()).severe(e.toString());
+ // handler.release();
+ // }
}
}
*/
@Override
public void actionPerformed(ActionEvent e) {
- Xcos.getInstance().open(null, null);
+ Xcos.getInstance().open(null, 0);
}
}
final File onlySelected = fc.getSelectedFile();
if (onlySelected != null) {
- Xcos.getInstance().open(onlySelected.getCanonicalPath(), null);
+ Xcos.getInstance().open(onlySelected.getCanonicalPath(), 0);
}
final File[] multiSelected = fc.getSelectedFiles();
for (File file : multiSelected) {
if (file != onlySelected) {
- Xcos.getInstance().open(file.getCanonicalPath(), null);
+ Xcos.getInstance().open(file.getCanonicalPath(), 0);
}
}
}
@Override
public void actionPerformed(ActionEvent e) {
try {
- Xcos.getInstance().open(recentFile.getCanonicalPath(), null);
+ Xcos.getInstance().open(recentFile.getCanonicalPath(), 0);
} catch (IOException e1) {
e1.printStackTrace();
}
import org.scilab.modules.gui.bridge.filechooser.SwingScilabFileChooser;
import org.scilab.modules.gui.filechooser.ScilabFileChooser;
import org.scilab.modules.gui.menuitem.MenuItem;
-import org.scilab.modules.xcos.Xcos;
import org.scilab.modules.xcos.graph.XcosDiagram;
import org.scilab.modules.xcos.io.XcosFileType;
import org.scilab.modules.xcos.utils.XcosMessages;
final XcosDiagram graph = (XcosDiagram) getGraph(null);
if (graph.saveDiagramAs(null)) {
graph.setModified(false);
- Xcos.getInstance().addDiagram(graph.getSavedFile(), graph);
}
}
package org.scilab.modules.xcos.actions;
-import static org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.asynchronousScilabExec;
-import static org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.buildCall;
-
import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.io.IOException;
-import java.util.logging.Logger;
import javax.swing.JButton;
-import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.InterpreterException;
-import org.scilab.modules.graph.ScilabComponent;
import org.scilab.modules.graph.ScilabGraph;
import org.scilab.modules.graph.actions.base.GraphActionManager;
import org.scilab.modules.graph.actions.base.OneBlockDependantAction;
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.xcos.graph.XcosDiagram;
-import org.scilab.modules.xcos.io.scicos.ScilabDirectHandler;
import org.scilab.modules.xcos.utils.XcosMessages;
/**
public void actionPerformed(ActionEvent e) {
final XcosDiagram graph = (XcosDiagram) getGraph(e);
String cmd;
-
- // action disabled when the cell is edited
- final ScilabComponent comp = ((ScilabComponent) graph.getAsComponent());
- if (comp.isEditing()) {
- return;
- }
-
- final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
- if (handler == null) {
- return;
- }
-
- updateUI(true);
-
- try {
- cmd = createSimulationCommand(graph, handler);
- } catch (IOException ex) {
- Logger.getLogger(StartAction.class.getName()).severe(ex.toString());
- updateUI(false);
-
- handler.release();
- return;
- }
-
- final ActionListener action = new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- updateUI(false);
- graph.getEngine().setCompilationNeeded(false);
-
- handler.release();
- }
- };
-
- try {
- asynchronousScilabExec(action, cmd);
- } catch (InterpreterException e1) {
- e1.printStackTrace();
- updateUI(false);
-
- handler.release();
- }
+ //FIXME: implement the compilation then simulation
+ // // action disabled when the cell is edited
+ // final ScilabComponent comp = ((ScilabComponent) graph.getAsComponent());
+ // if (comp.isEditing()) {
+ // return;
+ // }
+ //
+ // final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
+ // if (handler == null) {
+ // return;
+ // }
+ //
+ // updateUI(true);
+ //
+ // try {
+ // cmd = createSimulationCommand(graph, handler);
+ // } catch (IOException ex) {
+ // Logger.getLogger(StartAction.class.getName()).severe(ex.toString());
+ // updateUI(false);
+ //
+ // handler.release();
+ // return;
+ // }
+ //
+ // final ActionListener action = new ActionListener() {
+ // @Override
+ // public void actionPerformed(ActionEvent e) {
+ // updateUI(false);
+ //
+ // handler.release();
+ // }
+ // };
+ //
+ // try {
+ // asynchronousScilabExec(action, cmd);
+ // } catch (InterpreterException e1) {
+ // e1.printStackTrace();
+ // updateUI(false);
+ //
+ // handler.release();
+ // }
}
- /**
- * Create the command String
- *
- * @param diagram
- * the working diagram
- * @param handler
- * the handler use to communicate with Scilab
- * @return the command string
- * @throws IOException
- * when temporary files must not be created.
- */
- private String createSimulationCommand(final XcosDiagram diagram, final ScilabDirectHandler handler) throws IOException {
- String cmd;
- final StringBuilder command = new StringBuilder();
-
- /*
- * Log compilation info
- */
- final Logger log = Logger.getLogger(StartAction.class.getName());
- log.finest("start simulation");
-
- /*
- * Import a valid scs_m structure into Scilab
- */
- handler.writeDiagram(diagram);
- command.append(buildCall("scicos_debug", diagram.getScicosParameters().getDebugLevel()));
-
- /*
- * Simulate
- */
- command.append("xcos_simulate(scs_m, 4); ");
-
- cmd = command.toString();
- return cmd;
- }
-
- /**
- * Update the UI depending on the action selected or not
- *
- * @param started
- * the started status
- */
- public void updateUI(boolean started) {
- GraphActionManager.setEnable(StartAction.class, !started);
- GraphActionManager.setEnable(StopAction.class, false);
- ((XcosDiagram) getGraph(null)).setReadOnly(started);
-
- if (started) {
- ((XcosDiagram) getGraph(null)).info(XcosMessages.SIMULATION_IN_PROGRESS);
- } else {
- ((XcosDiagram) getGraph(null)).info(XcosMessages.EMPTY_INFO);
- }
- }
+ // /**
+ // * Create the command String
+ // *
+ // * @param diagram
+ // * the working diagram
+ // * @param handler
+ // * the handler use to communicate with Scilab
+ // * @return the command string
+ // * @throws IOException
+ // * when temporary files must not be created.
+ // */
+ // private String createSimulationCommand(final XcosDiagram diagram, final ScilabDirectHandler handler) throws IOException {
+ // String cmd;
+ // final StringBuilder command = new StringBuilder();
+ //
+ // /*
+ // * Log compilation info
+ // */
+ // final Logger log = Logger.getLogger(StartAction.class.getName());
+ // log.finest("start simulation");
+ //
+ // /*
+ // * Import a valid scs_m structure into Scilab
+ // */
+ // handler.writeDiagram(diagram);
+ // command.append(buildCall("scicos_debug", diagram.getScicosParameters().getDebugLevel()));
+ //
+ // /*
+ // * Simulate
+ // */
+ // command.append("xcos_simulate(scs_m, 4); ");
+ //
+ // cmd = command.toString();
+ // return cmd;
+ // }
+ //
+ // /**
+ // * Update the UI depending on the action selected or not
+ // *
+ // * @param started
+ // * the started status
+ // */
+ // public void updateUI(boolean started) {
+ // GraphActionManager.setEnable(StartAction.class, !started);
+ // GraphActionManager.setEnable(StopAction.class, false);
+ // ((XcosDiagram) getGraph(null)).setReadOnly(started);
+ //
+ // if (started) {
+ // ((XcosDiagram) getGraph(null)).info(XcosMessages.SIMULATION_IN_PROGRESS);
+ // } else {
+ // ((XcosDiagram) getGraph(null)).info(XcosMessages.EMPTY_INFO);
+ // }
+ // }
}
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;
-import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement;
import org.scilab.modules.commons.gui.FindIconHelper;
import org.scilab.modules.gui.utils.ScilabSwingUtilities;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.VectorOfString;
import org.scilab.modules.xcos.actions.SetContextAction;
import org.scilab.modules.xcos.graph.ScicosParameters;
-import org.scilab.modules.xcos.graph.SuperBlockDiagram;
import org.scilab.modules.xcos.graph.XcosDiagram;
-import org.scilab.modules.xcos.io.scicos.ScilabDirectHandler;
import org.scilab.modules.xcos.utils.XcosMessages;
/**
/*
* Construct a text from a String array context
*/
- for (String s : parameters.getContext()) {
- contextArea.append(s + SHARED_NEW_LINE);
+ VectorOfString v = parameters.getContext(new JavaController());
+ final int len = (int) v.size();
+ for (int i = 0; i < len; i++) {
+ contextArea.append(v.get(i) + SHARED_NEW_LINE);
}
JScrollPane contextAreaScroll = new JScrollPane(contextArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
@Override
public void actionPerformed(ActionEvent e) {
try {
- final String[] context = contextArea.getText().split(SHARED_NEW_LINE);
- parameters.setContext(context);
-
- /*
- * Validate the context
- */
- final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
- if (handler == null) {
- return;
- }
- try {
- handler.writeContext(context);
- ScilabInterpreterManagement.putCommandInScilabQueue("script2var(" + ScilabDirectHandler.CONTEXT + ", struct()); ");
- } finally {
- handler.release();
+ final String context = contextArea.getText();
+ final VectorOfString v = new VectorOfString();
+
+ int off = 0;
+ int next = 0;
+ while ((next = context.indexOf('\n', off)) != -1) {
+ v.add(context.substring(off, next));
+ off = next + 1;
}
+ parameters.setContext(new JavaController(), v);
+
+ // FIXME : context validation is not handled yet
+ //
+ // /*
+ // * Validate the context
+ // */
+ // final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
+ // if (handler == null) {
+ // return;
+ // }
+ // try {
+ //
+ // ScilabInterpreterManagement.putCommandInScilabQueue("script2var(" + ScilabDirectHandler.CONTEXT + ", struct()); ");
+ // } finally {
+ // handler.release();
+ // }
dispose();
} catch (PropertyVetoException e2) {
/*
* if superblock is concerned, then regenerate child diagram.
*/
- if (rootGraph instanceof SuperBlockDiagram) {
- SuperBlockDiagram superBlockDiagram = (SuperBlockDiagram) rootGraph;
- superBlockDiagram.getContainer().invalidateRpar();
- }
+ // if (rootGraph instanceof SuperBlockDiagram) {
+ // SuperBlockDiagram superBlockDiagram = (SuperBlockDiagram) rootGraph;
+ // superBlockDiagram.getContainer().invalidateRpar();
+ // }
}
});
}
import org.scilab.modules.commons.gui.FindIconHelper;
import org.scilab.modules.gui.utils.ScilabSwingUtilities;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.VectorOfDouble;
import org.scilab.modules.xcos.actions.SetupAction;
import org.scilab.modules.xcos.graph.ScicosParameters;
import org.scilab.modules.xcos.graph.XcosDiagram;
*
* Also contains a field with enable modifier set.
*/
- private static class SolverDescriptor implements Comparable<SolverDescriptor> {
+ protected static class SolverDescriptor implements Comparable<SolverDescriptor> {
private final int number;
private final String name;
private final String tooltip;
private JFormattedTextField integratorRel;
private JFormattedTextField toleranceOnTime;
private JFormattedTextField maxIntegrationTime;
- private JComboBox solver;
+ private JComboBox<SolverDescriptor> solver;
private JFormattedTextField maxStepSize;
/**
*/
// CSOFF: JavaNCSS
private void initComponents() {
+ JavaController controller = new JavaController();
+
JLabel integrationLabel = new JLabel(XcosMessages.FINAL_INTEGRATION_TIME);
integration = new JFormattedTextField(CURRENT_FORMAT);
integration.setInputVerifier(VALIDATE_POSITIVE_DOUBLE);
- integration.setValue(new BigDecimal(parameters.getFinalIntegrationTime()));
+ integration.setValue(new BigDecimal(parameters.getProperties(controller).get(ScicosParameters.FINAL_INTEGRATION_TIME)));
JLabel rtsLabel = new JLabel(XcosMessages.REAL_TIME_SCALING);
rts = new JFormattedTextField(CURRENT_FORMAT);
rts.setInputVerifier(VALIDATE_POSITIVE_DOUBLE);
- rts.setValue(new BigDecimal(parameters.getRealTimeScaling()));
+ rts.setValue(new BigDecimal(parameters.getProperties(controller).get(ScicosParameters.REAL_TIME_SCALING)));
JLabel integratorAbsLabel = new JLabel(XcosMessages.INTEGRATOR_ABSOLUTE_TOLERANCE);
integrator = new JFormattedTextField(CURRENT_FORMAT);
integrator.setInputVerifier(VALIDATE_POSITIVE_DOUBLE);
- integrator.setValue(new BigDecimal(parameters.getIntegratorAbsoluteTolerance()));
+ integrator.setValue(new BigDecimal(parameters.getProperties(controller).get(ScicosParameters.INTEGRATOR_ABSOLUTE_TOLERANCE)));
JLabel integratorRelLabel = new JLabel(XcosMessages.INTEGRATOR_RELATIVE_TOLERANCE);
integratorRel = new JFormattedTextField(CURRENT_FORMAT);
integratorRel.setInputVerifier(VALIDATE_POSITIVE_DOUBLE);
- integratorRel.setValue(new BigDecimal(parameters.getIntegratorRelativeTolerance()));
+ integratorRel.setValue(new BigDecimal(parameters.getProperties(controller).get(ScicosParameters.INTEGRATOR_RELATIVE_TOLERANCE)));
JLabel toleranceOnTimeLabel = new JLabel(XcosMessages.TOLERANCE_ON_TIME);
toleranceOnTime = new JFormattedTextField(CURRENT_FORMAT);
toleranceOnTime.setInputVerifier(VALIDATE_POSITIVE_DOUBLE);
- toleranceOnTime.setValue(new BigDecimal(parameters.getToleranceOnTime()));
+ toleranceOnTime.setValue(new BigDecimal(parameters.getProperties(controller).get(ScicosParameters.TOLERANCE_ON_TIME)));
JLabel maxIntegrationTimeLabel = new JLabel(XcosMessages.MAX_INTEGRATION_TIME_INTERVAL);
maxIntegrationTime = new JFormattedTextField(CURRENT_FORMAT);
maxIntegrationTime.setInputVerifier(VALIDATE_POSITIVE_DOUBLE);
- maxIntegrationTime.setValue(new BigDecimal(parameters.getMaxIntegrationTimeInterval()));
+ maxIntegrationTime.setValue(new BigDecimal(parameters.getProperties(controller).get(ScicosParameters.MAX_INTEGRATION_TIME_INTERVAL)));
JLabel solverLabel = new JLabel(XcosMessages.SOLVER_CHOICE);
- solver = new JComboBox(AVAILABLE_SOLVERS);
- double solverValue = parameters.getSolver();
+ solver = new JComboBox<SolverDescriptor>(AVAILABLE_SOLVERS);
+ double solverValue = parameters.getProperties(controller).get(ScicosParameters.SOLVER);
final int currentIndex = Arrays.binarySearch(AVAILABLE_SOLVERS, new SolverDescriptor(solverValue));
final SolverDescriptor current = AVAILABLE_SOLVERS[currentIndex];
solver.setSelectedIndex(currentIndex);
final class ComboboxToolTipRenderer extends DefaultListCellRenderer {
@Override
- public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
+ public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
JComponent comp = (JComponent) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (-1 < index && null != value) {
JLabel maxStepSizeLabel = new JLabel(XcosMessages.MAXIMUN_STEP_SIZE);
maxStepSize = new JFormattedTextField(CURRENT_FORMAT);
maxStepSize.setInputVerifier(VALIDATE_POSITIVE_DOUBLE);
- maxStepSize.setValue(new BigDecimal(parameters.getMaximumStepSize()));
+ maxStepSize.setValue(new BigDecimal(parameters.getProperties(controller).get(ScicosParameters.MAXIMUM_STEP_SIZE)));
JButton cancelButton = new JButton(XcosMessages.CANCEL);
JButton okButton = new JButton(XcosMessages.OK);
defaultButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- integration.setValue(new BigDecimal(ScicosParameters.FINAL_INTEGRATION_TIME));
- rts.setValue(new BigDecimal(ScicosParameters.REAL_TIME_SCALING));
- integrator.setValue(new BigDecimal(ScicosParameters.INTEGRATOR_ABSOLUTE_TOLERANCE));
- integratorRel.setValue(new BigDecimal(ScicosParameters.INTEGRATOR_RELATIVE_TOLERANCE));
- toleranceOnTime.setValue(new BigDecimal(ScicosParameters.TOLERANCE_ON_TIME));
- maxIntegrationTime.setValue(new BigDecimal(ScicosParameters.MAX_INTEGRATION_TIME_INTERVAL));
- solver.setSelectedIndex((int) ScicosParameters.SOLVER);
- maxStepSize.setValue(new BigDecimal(ScicosParameters.MAXIMUM_STEP_SIZE));
+ integration.setValue(new BigDecimal(ScicosParameters.DEFAULT_PARAMETERS.get(ScicosParameters.FINAL_INTEGRATION_TIME)));
+ integrator.setValue(new BigDecimal(ScicosParameters.DEFAULT_PARAMETERS.get(ScicosParameters.INTEGRATOR_ABSOLUTE_TOLERANCE)));
+ integratorRel.setValue(new BigDecimal(ScicosParameters.DEFAULT_PARAMETERS.get(ScicosParameters.INTEGRATOR_RELATIVE_TOLERANCE)));
+ toleranceOnTime.setValue(new BigDecimal(ScicosParameters.DEFAULT_PARAMETERS.get(ScicosParameters.TOLERANCE_ON_TIME)));
+ maxIntegrationTime.setValue(new BigDecimal(ScicosParameters.DEFAULT_PARAMETERS.get(ScicosParameters.MAX_INTEGRATION_TIME_INTERVAL)));
+ maxStepSize.setValue(new BigDecimal(ScicosParameters.DEFAULT_PARAMETERS.get(ScicosParameters.MAXIMUM_STEP_SIZE)));
+ rts.setValue(new BigDecimal(ScicosParameters.DEFAULT_PARAMETERS.get(ScicosParameters.REAL_TIME_SCALING)));
+ solver.setSelectedIndex((int) ScicosParameters.DEFAULT_PARAMETERS.get(ScicosParameters.SOLVER));
}
});
* handler
*/
int solverSelectedIndex = solver.getSelectedIndex();
- parameters.setSolver(AVAILABLE_SOLVERS[solverSelectedIndex].getNumber());
-
- parameters.setFinalIntegrationTime(((BigDecimal) integration.getValue()).doubleValue());
- parameters.setRealTimeScaling(((BigDecimal) rts.getValue()).doubleValue());
- parameters.setIntegratorAbsoluteTolerance(((BigDecimal) integrator.getValue()).doubleValue());
- parameters.setIntegratorRelativeTolerance(((BigDecimal) integratorRel.getValue()).doubleValue());
- parameters.setToleranceOnTime(((BigDecimal) toleranceOnTime.getValue()).doubleValue());
- parameters.setMaxIntegrationTimeInterval(((BigDecimal) maxIntegrationTime.getValue()).doubleValue());
- parameters.setMaximumStepSize(((BigDecimal) maxStepSize.getValue()).doubleValue());
+
+ VectorOfDouble v = new VectorOfDouble();
+ v.set(ScicosParameters.FINAL_INTEGRATION_TIME, ((BigDecimal) integration.getValue()).doubleValue());
+ v.set(ScicosParameters.INTEGRATOR_ABSOLUTE_TOLERANCE, ((BigDecimal) integrator.getValue()).doubleValue());
+ v.set(ScicosParameters.INTEGRATOR_RELATIVE_TOLERANCE, ((BigDecimal) integratorRel.getValue()).doubleValue());
+ v.set(ScicosParameters.TOLERANCE_ON_TIME, ((BigDecimal) toleranceOnTime.getValue()).doubleValue());
+ v.set(ScicosParameters.MAX_INTEGRATION_TIME_INTERVAL, ((BigDecimal) maxIntegrationTime.getValue()).doubleValue());
+ v.set(ScicosParameters.MAXIMUM_STEP_SIZE, ((BigDecimal) maxStepSize.getValue()).doubleValue());
+ v.set(ScicosParameters.REAL_TIME_SCALING, ((BigDecimal) rts.getValue()).doubleValue());
+ v.set(ScicosParameters.SOLVER, AVAILABLE_SOLVERS[solverSelectedIndex].getNumber());
+
+ parameters.setProperties(new JavaController(), v);
dispose();
import javax.swing.Timer;
-import org.scilab.modules.graph.utils.Font;
import org.scilab.modules.graph.utils.ScilabExported;
import org.scilab.modules.graph.utils.StyleMap;
import org.scilab.modules.types.ScilabString;
-import org.scilab.modules.xcos.Xcos;
import org.scilab.modules.xcos.graph.XcosDiagram;
-import org.scilab.modules.xcos.io.scicos.AbstractElement;
import com.mxgraph.model.mxGeometry;
-import com.mxgraph.util.mxConstants;
import com.mxgraph.util.mxRectangle;
-import com.mxgraph.view.mxCellState;
-import com.mxgraph.view.mxGraphView;
/**
* Implement the AFFICH_m block
* Update and refresh the values
*/
private void update(String uid, String[][] data) {
- final Object cell = Xcos.getInstance().lookupForCell(new String[] { uid });
- if (cell != null) {
- final XcosDiagram diag = Xcos.findParent(cell);
- final String value = getText(data);
-
- diag.getModel().setValue(cell, value);
-
- final mxCellState state = diag.getView().getState(cell);
- if (state != null) {
- state.setLabel(value);
- }
-
- diag.getAsComponent().redraw(state);
- }
+ // FIXME re-implement this sheet
+ // final Object cell = Xcos.getInstance().lookupForCell(new String[] { uid });
+ // if (cell != null) {
+ // final XcosDiagram diag = Xcos.findParent(cell);
+ // final String value = getText(data);
+ //
+ // diag.getModel().setValue(cell, value);
+ //
+ // final mxCellState state = diag.getView().getState(cell);
+ // if (state != null) {
+ // state.setLabel(value);
+ // }
+ //
+ // diag.getAsComponent().redraw(state);
+ // }
}
/**
index = new int[] { PRECISION_INDEX, 0 };
final String width = data[index[0]][index[1]];
- AbstractElement.incrementIndexes(index, true);
+ // AbstractElement.incrementIndexes(index, true);
final String rational = data[index[0]][index[1]];
final String format = "%" + width + "." + rational + "f";
*/
int[] index = new int[] { 0, 0 };
final String data00 = data[index[0]][index[1]];
- if (data00.startsWith(OPENING_BRACKET)) {
- AbstractElement.incrementIndexes(index, true);
- }
+ // if (data00.startsWith(OPENING_BRACKET)) {
+ // AbstractElement.incrementIndexes(index, true);
+ // }
/*
* Apply style
*/
final StyleMap style = new StyleMap(src.getStyle());
- try {
- final int parsedFontInt = Integer.parseInt(data[index[0]][index[1]]);
- style.put(mxConstants.STYLE_FONTFAMILY, Font.getFont(parsedFontInt).getName());
-
- AbstractElement.incrementIndexes(index, true);
- final int parsedFontSizeInt = Integer.parseInt(data[index[0]][index[1]]);
- style.put(mxConstants.STYLE_FONTSIZE, Integer.toString(Font.getSize(parsedFontSizeInt)));
-
- AbstractElement.incrementIndexes(index, true);
- final int parsedFontColorInt = Integer.parseInt(data[index[0]][index[1]]);
- String color = "#" + Integer.toHexString(Font.getColor(parsedFontColorInt).getRGB());
- style.put(mxConstants.STYLE_FONTCOLOR, color);
- } catch (NumberFormatException e) {
- LOG.severe(e.toString());
- return;
- }
+ // try {
+ // final int parsedFontInt = Integer.parseInt(data[index[0]][index[1]]);
+ // style.put(mxConstants.STYLE_FONTFAMILY, Font.getFont(parsedFontInt).getName());
+ //
+ // AbstractElement.incrementIndexes(index, true);
+ // final int parsedFontSizeInt = Integer.parseInt(data[index[0]][index[1]]);
+ // style.put(mxConstants.STYLE_FONTSIZE, Integer.toString(Font.getSize(parsedFontSizeInt)));
+ //
+ // AbstractElement.incrementIndexes(index, true);
+ // final int parsedFontColorInt = Integer.parseInt(data[index[0]][index[1]]);
+ // String color = "#" + Integer.toHexString(Font.getColor(parsedFontColorInt).getRGB());
+ // style.put(mxConstants.STYLE_FONTCOLOR, color);
+ // } catch (NumberFormatException e) {
+ // LOG.severe(e.toString());
+ // return;
+ // }
src.setStyle(style.toString());
}
}
/** Default constructor */
- public AfficheBlock() {
- super();
-
- getParametersPCS().addPropertyChangeListener(EXPRS, UpdateStyle.getInstance());
- }
-
- /**
- * Set the default values
- *
- * @see org.scilab.modules.xcos.block.BasicBlock#setDefaultValues()
- */
- @Override
- protected void setDefaultValues() {
- super.setDefaultValues();
-
- setValue("0.0");
+ public AfficheBlock(long uid) {
+ super(uid);
}
/**
package org.scilab.modules.xcos.block;
-import java.awt.Cursor;
import java.awt.MouseInfo;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.ArrayList;
-import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import org.scilab.modules.action_binding.InterpreterManagement;
-import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement;
-import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.InterpreterException;
import org.scilab.modules.graph.ScilabGraph;
import org.scilab.modules.graph.ScilabGraphUniqueObject;
import org.scilab.modules.graph.actions.CopyAction;
import org.scilab.modules.graph.actions.DeleteAction;
import org.scilab.modules.graph.actions.base.DefaultAction;
import org.scilab.modules.graph.utils.ScilabGraphConstants;
-import org.scilab.modules.graph.utils.StyleMap;
import org.scilab.modules.gui.bridge.contextmenu.SwingScilabContextMenu;
import org.scilab.modules.gui.contextmenu.ContextMenu;
import org.scilab.modules.gui.contextmenu.ScilabContextMenu;
import org.scilab.modules.gui.menu.ScilabMenu;
import org.scilab.modules.gui.menuitem.MenuItem;
import org.scilab.modules.gui.menuitem.ScilabMenuItem;
-import org.scilab.modules.types.ScilabDouble;
-import org.scilab.modules.types.ScilabList;
-import org.scilab.modules.types.ScilabMList;
-import org.scilab.modules.types.ScilabString;
-import org.scilab.modules.types.ScilabType;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.Kind;
+import org.scilab.modules.xcos.ObjectProperties;
import org.scilab.modules.xcos.Xcos;
import org.scilab.modules.xcos.XcosTab;
import org.scilab.modules.xcos.actions.EditFormatAction;
import org.scilab.modules.xcos.block.actions.alignement.AlignBlockActionMiddle;
import org.scilab.modules.xcos.block.actions.alignement.AlignBlockActionRight;
import org.scilab.modules.xcos.block.actions.alignement.AlignBlockActionTop;
-import org.scilab.modules.xcos.graph.PaletteDiagram;
-import org.scilab.modules.xcos.graph.SuperBlockDiagram;
import org.scilab.modules.xcos.graph.XcosDiagram;
import org.scilab.modules.xcos.io.scicos.BasicBlockInfo;
-import org.scilab.modules.xcos.io.scicos.DiagramElement;
-import org.scilab.modules.xcos.io.scicos.ScicosFormatException;
-import org.scilab.modules.xcos.io.scicos.ScilabDirectHandler;
import org.scilab.modules.xcos.port.BasicPort;
import org.scilab.modules.xcos.port.command.CommandPort;
import org.scilab.modules.xcos.port.control.ControlPort;
import org.scilab.modules.xcos.port.output.OutputPort;
import org.scilab.modules.xcos.utils.BlockPositioning;
import org.scilab.modules.xcos.utils.XcosConstants;
-import org.scilab.modules.xcos.utils.XcosEvent;
import org.scilab.modules.xcos.utils.XcosMessages;
import com.mxgraph.model.mxGeometry;
import com.mxgraph.model.mxICell;
-import com.mxgraph.model.mxIGraphModel;
-import com.mxgraph.util.mxConstants;
-import com.mxgraph.util.mxEventObject;
-import com.mxgraph.util.mxUtils;
/**
* A block on the diagram
*/
-// CSOFF: ClassDataAbstractionCoupling
-// CSOFF: ClassFanOutComplexity
@SuppressWarnings(value = { "serial" })
public class BasicBlock extends ScilabGraphUniqueObject implements Serializable {
/**
private static final Class<?>[] sortedChildrenClass = {InputPort.class, OutputPort.class, ControlPort.class, CommandPort.class, Object.class};
/*
- * Property names
- */
-
- /**
- * Property name of interfaceFunctionName
- */
- public static final String INTERFACE_FUNCTION_NAME = "interfaceFunctionName";
- /**
- * Property name of simulationFunctionName
- */
- public static final String SIMULATION_FUNCTION_NAME = "simulationFunctionName";
- /**
- * Property name of simulationFunctionType
- */
- public static final String SIMULATION_FUNCTION_TYPE = "simulationFunctionType";
- /**
- * Property name of realParameters
- */
- public static final String REAL_PARAMETERS = "realParameters";
- /**
- * Property name of integerParameters
- */
- public static final String INTEGER_PARAMETERS = "integerParameters";
- /**
- * Property name of objectsParameters
- */
- public static final String OBJECTS_PARAMETERS = "objectsParameters";
- /**
- * Property name of dependsOnU
- */
- public static final String DEPENDS_ON_U = "dependsOnU";
- /**
- * Property name of dependsOnT
- */
- public static final String DEPENDS_ON_T = "dependsOnT";
- /**
- * Property name of blockType
- */
- public static final String BLOCK_TYPE = "blockType";
- /**
- * Property name of ordering
- */
- public static final String ORDERING = "ordering";
- /**
- * Property name of exprs
- */
- public static final String EXPRS = "exprs";
- /**
- * Property name of nbZerosCrossing
- */
- public static final String NB_ZEROS_CROSSING = "nbZerosCrossing";
- /**
- * Property name of nmode
- */
- public static final String NMODE = "nmode";
- /**
- * Property name of state
- */
- public static final String STATE = "state";
- /**
- * Property name of dState
- */
- public static final String D_STATE = "dState";
- /**
- * Property name of oDState
- */
- public static final String O_D_STATE = "oDState";
- /**
- * Property name of equations
- */
- public static final String EQUATIONS = "equations";
-
- /*
* Default values
*/
* Local constants
*/
- private static final String PARENT_DIAGRAM_WAS_NULL = "Parent diagram was null";
private static final double DEFAULT_POSITION_X = 10.0;
private static final double DEFAULT_POSITION_Y = 10.0;
private static final double DEFAULT_WIDTH = 40.0;
private static final double DEFAULT_HEIGHT = 40.0;
- private static final PropertyChangeListener STYLE_UPDATER = new UpdateStyleFromInterfunction();
- private static final Logger LOG = Logger.getLogger(BasicBlock.class.getName());
-
/**
* Sort the children list in place.
*
public int compare(Object o1, Object o2) {
// diff is the major sorting by kind
int diff = compareByChildClass(o1, o2);
-
if (o1 instanceof BasicPort && o2 instanceof BasicPort) {
// first sort with the port list index
final int diffIndexOf = Integer.signum(reference.indexOf(o1) - reference.indexOf(o2));
return base * (Integer.MAX_VALUE / sortedChildrenClass.length);
}
- /**
- * Manage events for block parameters.
- *
- * The property name is the field name, is one of:
- * <ol>
- * <li>"interfaceFunctionName"
- * <li>"simulationFunctionName"
- * <li>"simulationFunctionType"
- * <li>"exprs"
- * <li>"realParameters"
- * <li>"integerParameters"
- * <li>"objectsParameters"
- * <li>"nbZerosCrossing"
- * <li>"nmode"
- * <li>"state"
- * <li>"dState"
- * <li>"oDState"
- * <li>"equations"
- * <li>"dependsOnU"
- * <li>"dependsOnT"
- * <li>"blockType"
- * <li>"ordering"
- * </ol>
- *
- * you can easily access to then by using property name constants.
- */
- private PropertyChangeSupport parametersPCS = new PropertyChangeSupport(this);
-
- private String interfaceFunctionName = DEFAULT_INTERFACE_FUNCTION;
- private String simulationFunctionName = DEFAULT_SIMULATION_FUNCTION;
- private SimulationFunctionType simulationFunctionType = SimulationFunctionType.DEFAULT;
- private transient XcosDiagram parentDiagram;
-
- private int angle;
- private boolean isFlipped;
- private boolean isMirrored;
-
- // TODO : Must make this types evolve, but for now keep a strong link to
- // Scilab
- // !! WARNING !!
- // exprs = [] ; rpar = [] ; ipar = [] ; opar = list()
-
- // private List<String> exprs = new ArrayList<String>();
- private ScilabType exprs;
- // private List<Double> realParameters = new ArrayList<Double>();
- private ScilabType realParameters;
- /**
- * Update status on the rpar mlist, if true then a re-encode has to be performed on the getter.
- */
- protected boolean hasAValidRpar = false;
- // private List<Integer> integerParameters = new ArrayList<Integer>();
- private ScilabType integerParameters;
- // private List objectsParameters = new ArrayList();
- private ScilabType objectsParameters;
-
- private ScilabType nbZerosCrossing = new ScilabDouble();
-
- private ScilabType nmode = new ScilabDouble();
-
- private ScilabType state = new ScilabDouble();
- private ScilabType dState = new ScilabDouble();
- private ScilabType oDState = new ScilabDouble();
-
- private ScilabType equations;
-
- private boolean dependsOnU;
- private boolean dependsOnT;
-
- private String blockType = "c";
-
- private int ordering;
private boolean locked;
+ private final long uid;
/**
* Represent a simulation function type compatible with Scilab/Scicos
};
/**
- * Update the source block when the interfunction change.
- */
- private static final class UpdateStyleFromInterfunction implements PropertyChangeListener, Serializable {
-
- /**
- * Default constructor.
- */
- public UpdateStyleFromInterfunction() {
- }
-
- /**
- * Update the label on interfunction change.
- *
- * @param evt
- * the property change event.
- * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
- */
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
- final BasicBlock source = (BasicBlock) evt.getSource();
-
- /*
- * Put the interfunction at the start of the style map to preserve
- * style modification.
- *
- * oldStyle="SUPER_f;fillColor=red" newStyle="DSUPER;fillColor=red"
- *
- * and not newStyle="fillColor=red;DSUPER"
- */
- final StyleMap style = new StyleMap((String) evt.getNewValue());
- style.putAll(source.getStyle());
- style.remove(evt.getOldValue());
-
- source.setStyle(style.toString());
- }
-
- }
-
- /**
- * Trace the parameters change on the {@link Logger}.
- *
- * This listener is only installed if the trace is enable.
- */
- private static final class TraceParametersListener implements PropertyChangeListener, Serializable {
- private static TraceParametersListener instance;
-
- /**
- * Default constructor.
- */
- private TraceParametersListener() {
- super();
- }
-
- /**
- * @return the instance
- */
- public static TraceParametersListener getInstance() {
- if (instance == null) {
- instance = new TraceParametersListener();
- }
- return instance;
- }
-
- /**
- * Trace.
- *
- * @param evt
- * the event
- * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
- */
- @Override
- public void propertyChange(PropertyChangeEvent evt) {
- if (LOG.isLoggable(Level.FINEST)) {
- LOG.finest(evt.getPropertyName() + ": " + evt.getOldValue() + ", " + evt.getNewValue());
- }
- }
- }
-
- /**
* Default constructor.
*/
- public BasicBlock() {
+ public BasicBlock(long uid) {
super();
- setDefaultValues();
- setVisible(true);
- setVertex(true);
-
- if (getStyle().isEmpty() && !getInterfaceFunctionName().isEmpty()) {
- setStyle(getInterfaceFunctionName());
- }
-
- parametersPCS.addPropertyChangeListener(INTERFACE_FUNCTION_NAME, STYLE_UPDATER);
/*
- * Trace block parameters change if applicable.
+ * Default parameters for blocks
*/
- if (LOG.isLoggable(Level.FINEST)) {
- parametersPCS.addPropertyChangeListener(TraceParametersListener.getInstance());
- }
- }
-
- /**
- * @param label
- * block label
- */
- protected BasicBlock(String label) {
- this();
- setDefaultValues();
- }
+ this.visible = true;
+ this.vertex = true;
+ this.connectable = false;
+ this.geometry = new mxGeometry(DEFAULT_POSITION_X, DEFAULT_POSITION_Y, DEFAULT_WIDTH, DEFAULT_HEIGHT);
- /**
- * @param label
- * block label
- * @param style
- * initial style
- */
- protected BasicBlock(String label, String style) {
- this(label);
- setStyle(style);
+ this.uid = uid;
}
/**
- * Initialize the block with the default values
+ * @return associated MVC ID
*/
- protected void setDefaultValues() {
- setVisible(true);
- setVertex(true);
- setConnectable(false);
- setGeometry(new mxGeometry(DEFAULT_POSITION_X, DEFAULT_POSITION_Y, DEFAULT_WIDTH, DEFAULT_HEIGHT));
- setValue("");
- setStyle("");
+ public long getUID() {
+ return uid;
}
/**
- * @return parent diagram
+ * @return the parent diagram of this graphical object
*/
public XcosDiagram getParentDiagram() {
- return parentDiagram;
- }
-
- /**
- * @param parentDiagram
- * parent diagram
- */
- public void setParentDiagram(XcosDiagram parentDiagram) {
- this.parentDiagram = parentDiagram;
- }
-
- /**
- * @return interface function name
- */
- public String getInterfaceFunctionName() {
- return interfaceFunctionName;
- }
-
- /**
- * @param interfaceFunctionName
- * interface function name
- */
- public void setInterfaceFunctionName(String interfaceFunctionName) {
- if ((this.interfaceFunctionName == null && interfaceFunctionName != null) || !this.interfaceFunctionName.equals(interfaceFunctionName)) {
-
- final String oldValue = this.interfaceFunctionName;
- this.interfaceFunctionName = interfaceFunctionName;
- parametersPCS.firePropertyChange(INTERFACE_FUNCTION_NAME, oldValue, interfaceFunctionName);
- }
- }
-
- /**
- * @param simulationFunctionName
- * sumulation function name
- */
- public void setSimulationFunctionName(String simulationFunctionName) {
- if ((this.simulationFunctionName == null && simulationFunctionName != null) || !this.simulationFunctionName.equals(simulationFunctionName)) {
-
- final String oldValue = this.simulationFunctionName;
- this.simulationFunctionName = simulationFunctionName;
- parametersPCS.firePropertyChange(SIMULATION_FUNCTION_NAME, oldValue, simulationFunctionName);
- }
- }
-
- /**
- * @return sumulation function name
- */
- public String getSimulationFunctionName() {
- return simulationFunctionName;
- }
-
- /**
- * @param scilabValue
- * simulation function type
- */
- public void setSimulationFunctionType(int scilabValue) {
- SimulationFunctionType simFunctionType = SimulationFunctionType.convertScilabValue(scilabValue);
- setSimulationFunctionType(simFunctionType);
- }
-
- /**
- * @param simulationFunctionType
- * simulation function type
- */
- public void setSimulationFunctionType(SimulationFunctionType simulationFunctionType) {
- if ((this.simulationFunctionType == null && simulationFunctionType != null) || !this.simulationFunctionType.equals(simulationFunctionType)) {
-
- final SimulationFunctionType oldValue = this.simulationFunctionType;
- this.simulationFunctionType = simulationFunctionType;
- parametersPCS.firePropertyChange(SIMULATION_FUNCTION_TYPE, oldValue, simulationFunctionType);
- }
- }
-
- /**
- * @return simulation function type
- */
- public SimulationFunctionType getSimulationFunctionType() {
- return simulationFunctionType;
- }
-
- /**
- * @return real parameter ( rpar )
- */
- public ScilabType getRealParameters() {
- if (!hasAValidRpar && realParameters instanceof ScilabMList) {
- try {
- final DiagramElement elem = new DiagramElement();
- final XcosDiagram d = elem.decode(realParameters, new XcosDiagram(false));
- realParameters = elem.encode(d, null);
- } catch (ScicosFormatException e) {
- // do nothing on error (no assignation)
- }
- }
-
- return realParameters;
- }
-
- /**
- * @param realParameters
- * reaL parameter ( rpar )
- */
- public void setRealParameters(ScilabType realParameters) {
- if ((this.realParameters == null && realParameters != null) || !this.realParameters.equals(realParameters)) {
-
- final ScilabType oldValue = this.realParameters;
- this.realParameters = realParameters;
- parametersPCS.firePropertyChange(REAL_PARAMETERS, oldValue, realParameters);
- }
- }
-
- /**
- * Invalide the rpar, a new child diagram encoding will be performed on
- * demand.
- */
- public void invalidateRpar() {
- hasAValidRpar = false;
- }
-
- /**
- * @return integer parameter ( ipar )
- */
- public ScilabType getIntegerParameters() {
- return integerParameters;
- }
-
- /**
- * @param integerParameters
- * integer parameter ( ipar )
- */
- public void setIntegerParameters(ScilabType integerParameters) {
- if ((this.integerParameters == null && integerParameters != null) || !this.integerParameters.equals(integerParameters)) {
-
- final ScilabType oldValue = this.integerParameters;
- this.integerParameters = integerParameters;
- parametersPCS.firePropertyChange(INTEGER_PARAMETERS, oldValue, integerParameters);
- }
- }
-
- /**
- * @return object parameter ( opar )
- */
- public ScilabType getObjectsParameters() {
- return objectsParameters;
- }
-
- /**
- * @param objectsParameters
- * object parameter ( opar )
- */
- public void setObjectsParameters(ScilabType objectsParameters) {
- if ((this.objectsParameters == null && objectsParameters != null) || !this.objectsParameters.equals(objectsParameters)) {
-
- final ScilabType oldValue = this.objectsParameters;
- this.objectsParameters = objectsParameters;
- parametersPCS.firePropertyChange(OBJECTS_PARAMETERS, oldValue, objectsParameters);
- }
- }
-
- /**
- * @param dependsOnU
- * ?
- */
- public void setDependsOnU(boolean dependsOnU) {
- if (this.dependsOnU != dependsOnU) {
-
- final boolean oldValue = this.dependsOnU;
- this.dependsOnU = dependsOnU;
- parametersPCS.firePropertyChange(DEPENDS_ON_U, oldValue, dependsOnU);
- }
- }
-
- /**
- * @return ?
- */
- public boolean isDependsOnU() {
- return dependsOnU;
- }
-
- /**
- * @param dependsOnT
- * ?
- */
- public void setDependsOnT(boolean dependsOnT) {
- if (this.dependsOnT != dependsOnT) {
-
- final boolean oldValue = this.dependsOnT;
- this.dependsOnT = dependsOnT;
- parametersPCS.firePropertyChange(DEPENDS_ON_T, oldValue, dependsOnT);
- }
- }
-
- /**
- * @return ?
- */
- public boolean isDependsOnT() {
- return dependsOnT;
- }
-
- /**
- * @param blockType
- * block type
- */
- public void setBlockType(String blockType) {
- if ((this.blockType == null && blockType != null) || !this.blockType.equals(blockType)) {
-
- final String oldValue = this.blockType;
- this.blockType = blockType;
- parametersPCS.firePropertyChange(BLOCK_TYPE, oldValue, blockType);
- }
- }
-
- /**
- * @return block type
- */
- public String getBlockType() {
- return blockType;
- }
-
- /**
- * @param ordering
- * order value
- */
- public void setOrdering(int ordering) {
- if (this.ordering != ordering) {
-
- final int oldValue = this.ordering;
- this.ordering = ordering;
- parametersPCS.firePropertyChange(ORDERING, oldValue, ordering);
- }
- }
-
- /**
- * @return order value
- */
- public int getOrdering() {
- return ordering;
- }
-
- /**
- * @param exprs
- * expression
- */
- public void setExprs(ScilabType exprs) {
- if ((this.exprs == null && exprs != null) || !this.exprs.equals(exprs)) {
-
- final ScilabType oldValue = this.exprs;
- this.exprs = exprs;
- parametersPCS.firePropertyChange(EXPRS, oldValue, exprs);
- }
- }
-
- /**
- * @return expression
- */
- public ScilabType getExprs() {
- return exprs;
- }
-
- /**
- * @return the expression as an object array
- */
- public Object[] getExprsFormat() {
- // evaluate emptiness
- if (getExprs() == null || getExprs().isEmpty() || getExprs().getHeight() == 0 || getExprs().getWidth() == 0) {
- return new String[0];
- }
-
- List<String[]> stack = getString(null, getExprs());
-
- int len = 0;
- for (Object[] strings : stack) {
- len += strings.length;
- }
-
- final Object[] array = new Object[len];
- int start = 0;
- for (Object[] strings : stack) {
- System.arraycopy(strings, 0, array, start, strings.length);
- start += strings.length;
- }
-
- return array;
- }
-
- /**
- * Append the data recursively to the stack
- *
- * @param currentStack
- * the current stack
- * @param data
- * the data to append
- * @return the stack
- */
- private List<String[]> getString(List<String[]> currentStack, ScilabType data) {
- final List<String[]> stack;
-
- if (currentStack == null) {
- stack = new LinkedList<String[]>();
+ /*
+ * Retrieve the parent
+ */
+ long[] parentBlock = new long[0];
+ long[] parentDiagram = new long[0];
+ JavaController controller = new JavaController();
+ controller.getObjectProperty(getUID(), Kind.BLOCK, ObjectProperties.PARENT_BLOCK, parentBlock);
+ controller.getObjectProperty(getUID(), Kind.BLOCK, ObjectProperties.PARENT_DIAGRAM, parentDiagram);
+
+ final long parent;
+ final Kind kind;
+ if (parentBlock[0] == 0l) {
+ parent = parentDiagram[0];
+ kind = Kind.DIAGRAM;
} else {
- stack = currentStack;
- }
-
- if (data instanceof List) {
- /*
- * Container case (ScilabList, ScilabMList, ScilabTList)
- */
-
- @SuppressWarnings("unchecked")
- final List<ScilabType> list = (List<ScilabType>) data;
-
- for (final ScilabType scilabType : list) {
- getString(stack, scilabType);
- }
- } else if (data instanceof ScilabString) {
- /*
- * native case (only ScilabString supported)
- */
-
- final String[][] scilabData = ((ScilabString) data).getData();
- final int height = data.getHeight();
- final int width = data.getWidth();
-
- final String[] array = new String[height * width];
- for (int i = 0; i < height; ++i) {
- System.arraycopy(scilabData[i], 0, array, i * width, width);
- }
-
- stack.add(array);
- }
-
- return stack;
- }
-
- /**
- * @return zero crossing value
- */
- public ScilabType getNbZerosCrossing() {
- return nbZerosCrossing;
- }
-
- /**
- * @param nbZerosCrossing
- * zero crossing value
- */
- public void setNbZerosCrossing(ScilabType nbZerosCrossing) {
- if ((this.nbZerosCrossing == null && nbZerosCrossing != null) || !this.nbZerosCrossing.equals(nbZerosCrossing)) {
-
- final ScilabType oldValue = this.nbZerosCrossing;
- this.nbZerosCrossing = nbZerosCrossing;
- parametersPCS.firePropertyChange(NB_ZEROS_CROSSING, oldValue, nbZerosCrossing);
- }
- }
-
- /**
- * @return nmode
- */
- public ScilabType getNmode() {
- return nmode;
- }
-
- /**
- * @param nmode
- * nmode
- */
- public void setNmode(ScilabType nmode) {
- if ((this.nmode == null && nmode != null) || !this.nmode.equals(nmode)) {
-
- final ScilabType oldValue = this.nmode;
- this.nmode = nmode;
- parametersPCS.firePropertyChange(NMODE, oldValue, nmode);
- }
- }
-
- /**
- * @return current state
- */
- public ScilabType getState() {
- return state;
- }
-
- /**
- * @param state
- * new state
- */
- public void setState(ScilabType state) {
- if ((this.state == null && state != null) || !this.state.equals(state)) {
-
- final ScilabType oldValue = this.state;
- this.state = state;
- parametersPCS.firePropertyChange(STATE, oldValue, state);
- }
- }
-
- /**
- * @return current dstate
- */
- public ScilabType getDState() {
- return dState;
- }
-
- /**
- * @param dState
- * new dstate
- */
- public void setDState(ScilabType dState) {
- if ((this.dState == null && dState != null) || !this.dState.equals(dState)) {
-
- final ScilabType oldValue = this.dState;
- this.dState = dState;
- parametersPCS.firePropertyChange(D_STATE, oldValue, dState);
+ parent = parentBlock[0];
+ kind = Kind.BLOCK;
}
- }
-
- /**
- * @return current ostate
- */
- public ScilabType getODState() {
- return oDState;
- }
- /**
- * @param oDState
- * new odstate
- */
- public void setODState(ScilabType oDState) {
- if ((this.oDState == null && oDState != null) || !this.oDState.equals(oDState)) {
-
- final ScilabType oldValue = this.oDState;
- this.oDState = oDState;
- parametersPCS.firePropertyChange(O_D_STATE, oldValue, oDState);
+ /*
+ * Retrieve and create on demand the corresponding Diagram
+ */
+ XcosDiagram diagram;
+ Collection<XcosDiagram> diagrams = Xcos.getInstance().getDiagrams(parentDiagram[0]);
+ Optional<XcosDiagram> optDiagram = diagrams.stream().filter(d -> d.getUId() == parent).findFirst();
+ if (optDiagram.isPresent()) {
+ diagram = optDiagram.get();
+ } else {
+ diagram = new XcosDiagram(parent, kind);
+ Xcos.getInstance().addDiagram(parentDiagram[0], diagram);
}
- }
- /**
- * @return equations
- */
- public ScilabType getEquations() {
- return equations;
- }
-
- /**
- * @param equations
- * equations
- */
- public void setEquations(ScilabType equations) {
- if ((this.equations == null && equations != null) || !this.equations.equals(equations)) {
-
- final ScilabType oldValue = this.equations;
- this.equations = equations;
- parametersPCS.firePropertyChange(EQUATIONS, oldValue, equations);
- }
+ return diagram;
}
/**
}
/**
- * @param port
- * to remove
- */
- public void removePort(BasicPort port) {
- if (port.getEdgeCount() != 0 && getParentDiagram() != null) {
- getParentDiagram().removeCells(new Object[] { port.getEdgeAt(0) });
- }
- remove(port);
- }
-
- /**
- * Add a port on the block.
- *
- * This call should only be used when a port reordering operation must be
- * performed.
- *
- * @param port
- * The port to be added to the block
- */
- public void addPort(BasicPort port) {
- insert(port);
- port.setOrdering(BasicBlockInfo.getAllTypedPorts(this, false, port.getClass()).size());
- BlockPositioning.updateBlockView(this);
- }
-
- /**
- * @return command ports initial state
- */
- public ScilabDouble getAllCommandPortsInitialStates() {
- final List<CommandPort> cmdPorts = BasicBlockInfo.getAllTypedPorts(this, false, CommandPort.class);
- if (cmdPorts.isEmpty()) {
- return new ScilabDouble();
- }
-
- double[][] data = new double[cmdPorts.size()][1];
- for (int i = 0; i < cmdPorts.size(); ++i) {
- data[i][0] = cmdPorts.get(i).getInitialState();
- }
-
- return new ScilabDouble(data);
- }
-
- /**
- * @return name and type of the simulation function
- */
- public ScilabType getSimulationFunctionNameAndType() {
- if (getSimulationFunctionType() == SimulationFunctionType.DEFAULT) {
- return new ScilabString(getSimulationFunctionName());
- }
- ScilabList data = new ScilabList();
-
- data.add(new ScilabString(getSimulationFunctionName()));
- data.add(new ScilabDouble(getSimulationFunctionType().getAsDouble()));
-
- return data;
- }
-
- /**
- * Does the block update and register on the undo manager
- *
- * @param modifiedBlock
- * the new settings
- */
- public void updateBlockSettings(BasicBlock modifiedBlock) {
- if (modifiedBlock == null) {
- return;
- }
-
- /*
- * Update the block settings
- */
- updateFields(modifiedBlock);
-
- /*
- * Update the children ports
- */
- updateChildren(modifiedBlock);
-
- /*
- * If the block is in a superblock then update it.
- */
- if (getParentDiagram() instanceof SuperBlockDiagram) {
- SuperBlock block = ((SuperBlockDiagram) getParentDiagram()).getContainer();
-
- XcosDiagram graph = block.getParentDiagram();
- if (graph == null) {
- setParentDiagram(Xcos.findParent(block));
- graph = block.getParentDiagram();
- LOG.finest(PARENT_DIAGRAM_WAS_NULL);
- }
-
- graph.fireEvent(new mxEventObject(XcosEvent.SUPER_BLOCK_UPDATED, XcosConstants.EVENT_BLOCK_UPDATED, block));
- }
- }
-
- /**
- * Update the instance field.
- *
- * @param modifiedBlock
- * the modified instance
- */
- private void updateFields(BasicBlock modifiedBlock) {
- if (modifiedBlock == null) {
- return;
- }
-
- setDependsOnT(modifiedBlock.isDependsOnT());
- setDependsOnU(modifiedBlock.isDependsOnU());
- setExprs(modifiedBlock.getExprs());
-
- setRealParameters(modifiedBlock.getRealParameters());
- setIntegerParameters(modifiedBlock.getIntegerParameters());
- setObjectsParameters(modifiedBlock.getObjectsParameters());
-
- setState(modifiedBlock.getState());
- setDState(modifiedBlock.getDState());
- setODState(modifiedBlock.getODState());
-
- setBlockType(modifiedBlock.getBlockType());
- setSimulationFunctionName(modifiedBlock.getSimulationFunctionName());
- setSimulationFunctionType(modifiedBlock.getSimulationFunctionType());
-
- setNbZerosCrossing(modifiedBlock.getNbZerosCrossing());
- setNmode(modifiedBlock.getNmode());
-
- setEquations(modifiedBlock.getEquations());
- setStyle(modifiedBlock.getStyle());
- }
-
- /**
* Update the children of the block.
*
* @param modifiedBlock
* the new block instance
*/
private void updateChildren(BasicBlock modifiedBlock) {
- if (modifiedBlock == null) {
- return;
- }
-
- XcosDiagram graph = getParentDiagram();
- if (graph == null) {
- setParentDiagram(Xcos.findParent(this));
- graph = getParentDiagram();
- LOG.finest(PARENT_DIAGRAM_WAS_NULL);
- }
-
- /*
- * Checked as port classes only
- */
- @SuppressWarnings("unchecked")
- Set < Class <? extends mxICell >> types = new HashSet < Class <? extends mxICell >> (Arrays.asList(InputPort.class, OutputPort.class, ControlPort.class,
- CommandPort.class));
-
- Map < Class <? extends mxICell > , Deque<mxICell >> annotatedOlds = getTypedChildren(types);
- Map < Class <? extends mxICell > , Deque<mxICell >> annotatedNews = modifiedBlock.getTypedChildren(types);
-
- getParentDiagram().getModel().beginUpdate();
- try {
- for (Class <? extends mxICell > klass : types) {
- final Deque<mxICell> olds = annotatedOlds.get(klass);
- final Deque<mxICell> news = annotatedNews.get(klass);
-
- // updated ports
- while (!olds.isEmpty() && !news.isEmpty()) {
- mxICell previous = olds.poll();
- mxICell modified = news.poll();
-
- final int previousIndex = children.indexOf(previous);
-
- // relink
- if (previous.getEdgeCount() != 0) {
- final mxICell edge = previous.getEdgeAt(0);
- final boolean isOutgoing = previous == edge.getTerminal(true);
- previous.removeEdge(edge, isOutgoing);
- modified.insertEdge(edge, isOutgoing);
- }
-
- getParentDiagram().removeCells(new Object[] { previous }, false);
- getParentDiagram().addCells(new Object[] { modified }, this, previousIndex);
-
- // Clone the geometry to avoid empty geometry on new cells.
- getParentDiagram().getModel().setGeometry(modified, (mxGeometry) previous.getGeometry().clone());
-
- }
-
- // removed ports
- if (!olds.isEmpty()) {
- getParentDiagram().removeCells(olds.toArray(), true);
- }
-
- // added ports
- if (!news.isEmpty()) {
- getParentDiagram().addCells(news.toArray(), this);
- }
- }
- } finally {
- getParentDiagram().getModel().endUpdate();
- }
+ // if (modifiedBlock == null) {
+ // return;
+ // }
+ //
+ // XcosDiagram graph = getParentDiagram();
+ // if (graph == null) {
+ // setParentDiagram(Xcos.findParent(this));
+ // graph = getParentDiagram();
+ // LOG.finest(PARENT_DIAGRAM_WAS_NULL);
+ // }
+ //
+ // /*
+ // * Checked as port classes only
+ // */
+ // @SuppressWarnings("unchecked")
+ // Set < Class <? extends mxICell >> types = new HashSet < Class <? extends mxICell >> (Arrays.asList(InputPort.class, OutputPort.class, ControlPort.class,
+ // CommandPort.class));
+ //
+ // Map < Class <? extends mxICell > , Deque<mxICell >> annotatedOlds = getTypedChildren(types);
+ // Map < Class <? extends mxICell > , Deque<mxICell >> annotatedNews = modifiedBlock.getTypedChildren(types);
+ //
+ // getParentDiagram().getModel().beginUpdate();
+ // try {
+ // for (Class <? extends mxICell > klass : types) {
+ // final Deque<mxICell> olds = annotatedOlds.get(klass);
+ // final Deque<mxICell> news = annotatedNews.get(klass);
+ //
+ // // updated ports
+ // while (!olds.isEmpty() && !news.isEmpty()) {
+ // mxICell previous = olds.poll();
+ // mxICell modified = news.poll();
+ //
+ // final int previousIndex = children.indexOf(previous);
+ //
+ // // relink
+ // if (previous.getEdgeCount() != 0) {
+ // final mxICell edge = previous.getEdgeAt(0);
+ // final boolean isOutgoing = previous == edge.getTerminal(true);
+ // previous.removeEdge(edge, isOutgoing);
+ // modified.insertEdge(edge, isOutgoing);
+ // }
+ //
+ // getParentDiagram().removeCells(new Object[] { previous }, false);
+ // getParentDiagram().addCells(new Object[] { modified }, this, previousIndex);
+ //
+ // // Clone the geometry to avoid empty geometry on new cells.
+ // getParentDiagram().getModel().setGeometry(modified, (mxGeometry) previous.getGeometry().clone());
+ //
+ // }
+ //
+ // // removed ports
+ // if (!olds.isEmpty()) {
+ // getParentDiagram().removeCells(olds.toArray(), true);
+ // }
+ //
+ // // added ports
+ // if (!news.isEmpty()) {
+ // getParentDiagram().addCells(news.toArray(), this);
+ // }
+ // }
+ // } finally {
+ // getParentDiagram().getModel().endUpdate();
+ // }
}
/**
* @param context
* parent diagram context
*/
- public void openBlockSettings(String[] context) {
- final XcosDiagram graph;
- if (getParentDiagram() == null) {
- setParentDiagram(Xcos.findParent(this));
- graph = getParentDiagram();
- LOG.finest(PARENT_DIAGRAM_WAS_NULL);
- } else {
- graph = getParentDiagram();
- }
- if (graph instanceof PaletteDiagram) {
- return;
- }
-
- if (context == null) {
- throw new IllegalArgumentException();
- }
-
- // prevent to open twice
- if (isLocked()) {
- return;
- }
-
- graph.setCellsLocked(true);
- graph.getAsComponent().getGraphControl().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
-
- // sort children according to the ordering parameter (useful on
- // scilab-5.2.x diagrams)
- sortChildren();
-
- final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
- if (handler == null) {
- return;
- }
-
- try {
- // Write scs_m
- handler.writeBlock(this);
- // Write context
- handler.writeContext(context);
-
- final ActionListener action = new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- LOG.finest("Updating data.");
-
- graph.getView().clear(this, true, true);
-
- // Now read new Block
- graph.getModel().beginUpdate();
- try {
- final BasicBlock modifiedBlock = handler.readBlock();
- updateBlockSettings(modifiedBlock);
-
- graph.fireEvent(new mxEventObject(XcosEvent.ADD_PORTS, XcosConstants.EVENT_BLOCK_UPDATED, BasicBlock.this));
- } catch (ScicosFormatException ex) {
- LOG.severe(ex.toString());
- } finally {
- graph.getModel().endUpdate();
- setLocked(false);
-
- handler.release();
-
- graph.getAsComponent().getGraphControl().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- graph.setCellsLocked(false);
- }
- }
- };
-
- setLocked(true);
- ScilabInterpreterManagement.asynchronousScilabExec(action, "blk = xcosBlockInterface", getInterfaceFunctionName().toCharArray(), "set",
- ScilabDirectHandler.BLK.toCharArray(), ScilabDirectHandler.CONTEXT.toCharArray());
- } catch (InterpreterException e) {
- LOG.severe(e.toString());
- setLocked(false);
-
- handler.release();
-
- graph.getAsComponent().getGraphControl().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
- graph.setCellsLocked(false);
- }
+ public void openBlockSettings() {
+ // FIXME: implement something
+ // final XcosDiagram graph;
+ // if (getParentDiagram() == null) {
+ // setParentDiagram(Xcos.findParent(this));
+ // graph = getParentDiagram();
+ // LOG.finest(PARENT_DIAGRAM_WAS_NULL);
+ // } else {
+ // graph = getParentDiagram();
+ // }
+ // if (graph instanceof PaletteDiagram) {
+ // return;
+ // }
+ //
+ // if (context == null) {
+ // throw new IllegalArgumentException();
+ // }
+ //
+ // // prevent to open twice
+ // if (isLocked()) {
+ // return;
+ // }
+ //
+ // graph.setCellsLocked(true);
+ // graph.getAsComponent().getGraphControl().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+ //
+ // // sort children according to the ordering parameter (useful on
+ // // scilab-5.2.x diagrams)
+ // sortChildren();
+ //
+ // final ScilabDirectHandler handler = ScilabDirectHandler.acquire();
+ // if (handler == null) {
+ // return;
+ // }
+ //
+ // try {
+ // // Write scs_m
+ // handler.writeBlock(this);
+ // // Write context
+ // handler.writeContext(context);
+ //
+ // final ActionListener action = new ActionListener() {
+ // @Override
+ // public void actionPerformed(ActionEvent e) {
+ // LOG.finest("Updating data.");
+ //
+ // graph.getView().clear(this, true, true);
+ //
+ // // Now read new Block
+ // graph.getModel().beginUpdate();
+ // try {
+ // final BasicBlock modifiedBlock = handler.readBlock();
+ // updateBlockSettings(modifiedBlock);
+ //
+ // graph.fireEvent(new mxEventObject(XcosEvent.ADD_PORTS, XcosConstants.EVENT_BLOCK_UPDATED, BasicBlock.this));
+ // } catch (ScicosFormatException ex) {
+ // LOG.severe(ex.toString());
+ // } finally {
+ // graph.getModel().endUpdate();
+ // setLocked(false);
+ //
+ // handler.release();
+ //
+ // graph.getAsComponent().getGraphControl().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ // graph.setCellsLocked(false);
+ // }
+ // }
+ // };
+ //
+ // setLocked(true);
+ // ScilabInterpreterManagement.asynchronousScilabExec(action, "blk = xcosBlockInterface", getInterfaceFunctionName().toCharArray(), "set",
+ // ScilabDirectHandler.BLK.toCharArray(), ScilabDirectHandler.CONTEXT.toCharArray());
+ // } catch (InterpreterException e) {
+ // LOG.severe(e.toString());
+ // setLocked(false);
+ //
+ // handler.release();
+ //
+ // graph.getAsComponent().getGraphControl().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ // graph.setCellsLocked(false);
+ // }
}
/**
public String getToolTipText() {
StringBuilder result = new StringBuilder();
result.append(ScilabGraphConstants.HTML_BEGIN);
- result.append("Block Name : " + getInterfaceFunctionName() + ScilabGraphConstants.HTML_NEWLINE);
- result.append("Simulation : " + getSimulationFunctionName() + ScilabGraphConstants.HTML_NEWLINE);
- if (getParentDiagram() instanceof PaletteDiagram) {
- if (getIntegerParameters() != null) {
- result.append("Integer parameters : " + getIntegerParameters() + ScilabGraphConstants.HTML_NEWLINE);
- }
-
- if (getRealParameters() != null && getRealParameters().getHeight() != 0 && getRealParameters().getWidth() != 0) {
- result.append("Real parameters : " + getRealParameters() + ScilabGraphConstants.HTML_NEWLINE);
- }
-
- if (getObjectsParameters() != null) {
- result.append("Object parameters : " + getObjectsParameters() + ScilabGraphConstants.HTML_NEWLINE);
- }
+ JavaController controller = new JavaController();
+
+ String[] interfaceFunctionName = new String[1];
+ controller.getObjectProperty(getUID(), Kind.BLOCK, ObjectProperties.INTERFACE_FUNCTION, interfaceFunctionName);
+ String[] simulationFunctionName = new String[1];
+ controller.getObjectProperty(getUID(), Kind.BLOCK, ObjectProperties.SIM_FUNCTION_NAME, simulationFunctionName);
+
+ result.append("Block Name : " + interfaceFunctionName[0] + ScilabGraphConstants.HTML_NEWLINE);
+ result.append("Simulation : " + simulationFunctionName[1] + ScilabGraphConstants.HTML_NEWLINE);
+
+ // if (getParentDiagram() instanceof PaletteDiagram) {
+ // if (getIntegerParameters() != null) {
+ // result.append("Integer parameters : " + getIntegerParameters() + ScilabGraphConstants.HTML_NEWLINE);
+ // }
+ //
+ // if (getRealParameters() != null && getRealParameters().getHeight() != 0 && getRealParameters().getWidth() != 0) {
+ // result.append("Real parameters : " + getRealParameters() + ScilabGraphConstants.HTML_NEWLINE);
+ // }
+ //
+ // if (getObjectsParameters() != null) {
+ // result.append("Object parameters : " + getObjectsParameters() + ScilabGraphConstants.HTML_NEWLINE);
+ // }
+ // } else {
+ result.append("UID : " + getId() + ScilabGraphConstants.HTML_NEWLINE);
+ final int length = getStyle().length();
+ result.append("Style : ");
+ if (length > XcosConstants.MAX_CHAR_IN_STYLE) {
+ result.append(getStyle().substring(0, XcosConstants.MAX_CHAR_IN_STYLE));
+ result.append(XcosMessages.DOTS);
} else {
- result.append("UID : " + getId() + ScilabGraphConstants.HTML_NEWLINE);
- final int length = getStyle().length();
- result.append("Style : ");
- if (length > XcosConstants.MAX_CHAR_IN_STYLE) {
- result.append(getStyle().substring(0, XcosConstants.MAX_CHAR_IN_STYLE));
- result.append(XcosMessages.DOTS);
- } else {
- result.append(getStyle());
- }
- result.append(ScilabGraphConstants.HTML_NEWLINE);
- result.append("Flip : " + getFlip() + ScilabGraphConstants.HTML_NEWLINE);
- result.append("Mirror : " + getMirror() + ScilabGraphConstants.HTML_NEWLINE);
- result.append("Input ports : " + BasicBlockInfo.getAllTypedPorts(this, false, InputPort.class).size() + ScilabGraphConstants.HTML_NEWLINE);
- result.append("Output ports : " + BasicBlockInfo.getAllTypedPorts(this, false, OutputPort.class).size() + ScilabGraphConstants.HTML_NEWLINE);
- result.append("Control ports : " + BasicBlockInfo.getAllTypedPorts(this, false, ControlPort.class).size() + ScilabGraphConstants.HTML_NEWLINE);
- result.append("Command ports : " + BasicBlockInfo.getAllTypedPorts(this, false, CommandPort.class).size() + ScilabGraphConstants.HTML_NEWLINE);
+ result.append(getStyle());
}
+ result.append(ScilabGraphConstants.HTML_NEWLINE);
+ result.append("Input ports : " + BasicBlockInfo.getAllTypedPorts(this, false, InputPort.class).size() + ScilabGraphConstants.HTML_NEWLINE);
+ result.append("Output ports : " + BasicBlockInfo.getAllTypedPorts(this, false, OutputPort.class).size() + ScilabGraphConstants.HTML_NEWLINE);
+ result.append("Control ports : " + BasicBlockInfo.getAllTypedPorts(this, false, ControlPort.class).size() + ScilabGraphConstants.HTML_NEWLINE);
+ result.append("Command ports : " + BasicBlockInfo.getAllTypedPorts(this, false, CommandPort.class).size() + ScilabGraphConstants.HTML_NEWLINE);
+ // }
result.append("x : " + getGeometry().getX() + ScilabGraphConstants.HTML_NEWLINE);
result.append("y : " + getGeometry().getY() + ScilabGraphConstants.HTML_NEWLINE);
*/
public void openContextMenu(ScilabGraph graph) {
ContextMenu menu = null;
- if (getParentDiagram() instanceof PaletteDiagram) {
- menu = createPaletteContextMenu(graph);
- } else {
- menu = createContextMenu(graph);
- }
+ // if (getParentDiagram() instanceof PaletteDiagram) {
+ // menu = createPaletteContextMenu(graph);
+ // } else {
+ menu = createContextMenu(graph);
+ // }
menu.setVisible(true);
}
addTo.setCallback(new CommonCallBack(XcosMessages.ADDTO_NEW_DIAGRAM) {
@Override
public void callBack() {
-
- XcosDiagram theDiagram = new XcosDiagram();
+ JavaController controller = new JavaController();
+ XcosDiagram theDiagram = new XcosDiagram(controller.createObject(Kind.DIAGRAM), Kind.DIAGRAM);
BasicBlock block = (BasicBlock) BlockFactory.createClone(BasicBlock.this);
theDiagram.getModel().add(theDiagram.getDefaultParent(), block, 0);
mxGeometry geom = BasicBlock.this.getGeometry();
setDefaultPosition(geom);
theDiagram.getModel().setGeometry(block, geom);
BlockPositioning.updateBlockView(block);
- block.setParentDiagram(theDiagram);
}
});
@Override
public void callBack() {
- InterpreterManagement.requestScilabExec("help " + getInterfaceFunctionName());
+ JavaController controller = new JavaController();
+ String[] interfaceFunctionName = new String[1];
+ controller.getObjectProperty(getUID(), Kind.BLOCK, ObjectProperties.INTERFACE_FUNCTION, interfaceFunctionName);
+
+ InterpreterManagement.requestScilabExec("help " + interfaceFunctionName[0]);
}
});
menu.add(help);
return menu;
}
- // CSON: JavaNCSS
-
- /**
- * @param flip
- * value
- */
- public void setFlip(boolean flip) {
- isFlipped = flip;
- if (getParentDiagram() != null) {
- final mxIGraphModel model = getParentDiagram().getModel();
- mxUtils.setCellStyles(model, new Object[] { this }, ScilabGraphConstants.STYLE_FLIP, Boolean.toString(flip));
- }
- }
-
/**
* Override this to customize contextual menu
*
// To be overridden by sub-classes
}
- /**
- * @return mirror value
- */
- public boolean getMirror() {
- return isMirrored;
- }
-
- /**
- * @param mirror
- * new mirror value
- */
- public void setMirror(boolean mirror) {
- isMirrored = mirror;
- if (getParentDiagram() != null) {
- final mxIGraphModel model = getParentDiagram().getModel();
- mxUtils.setCellStyles(model, new Object[] { this }, ScilabGraphConstants.STYLE_MIRROR, Boolean.toString(mirror));
- }
- }
-
- /**
- * @return flip status
- */
- public boolean getFlip() {
- return isFlipped;
- }
-
- /**
- * invert flip status
- */
- public void toggleFlip() {
- BlockPositioning.toggleFlip(this);
- }
-
- /**
- * invert mirror value
- */
- public void toggleMirror() {
- BlockPositioning.toggleMirror(this);
- }
-
- /**
- *
- */
- public void toggleAntiClockwiseRotation() {
- BlockPositioning.toggleAntiClockwiseRotation(this);
-
- }
-
- /**
- * @return current angle
- */
- public int getAngle() {
- return angle;
- }
-
- /**
- * @param angle
- * new block angle
- */
- public void setAngle(int angle) {
- this.angle = angle;
-
- if (getParentDiagram() != null) {
- mxUtils.setCellStyles(getParentDiagram().getModel(), new Object[] { this }, mxConstants.STYLE_ROTATION, Integer.toString(angle));
- }
- }
-
- /**
- * Useful when we need to update local properties with mxCell style
- * properties
- */
- public void updateFieldsFromStyle() {
- StyleMap map = new StyleMap(getStyle());
-
- if (map.get(mxConstants.STYLE_ROTATION) != null) {
- angle = Integer.parseInt(map.get(mxConstants.STYLE_ROTATION));
- } else {
- angle = 0;
- }
-
- isFlipped = Boolean.parseBoolean(map.get(ScilabGraphConstants.STYLE_FLIP));
- isMirrored = Boolean.parseBoolean(map.get(ScilabGraphConstants.STYLE_MIRROR));
- }
/**
* Set the default block position on the geom
geom.setY(DEFAULT_POSITION_Y);
}
- /**
- * Get the parameters change support.
- *
- * The property name for each event is the field name, so one of: -
- * "interfaceFunctionName" - "simulationFunctionName" -
- * "simulationFunctionType" - "exprs" - "realParameters" -
- * "integerParameters" - "objectsParameters" - "nbZerosCrossing" - "nmode" -
- * "state" - "dState" - "oDState" - "equations" - "dependsOnU" -
- * "dependsOnT" - "blockType" - "ordering"
- *
- * @return the associated {@link PropertyChangeSupport} instance
- */
- protected PropertyChangeSupport getParametersPCS() {
- return parametersPCS;
- }
-
/*
* Overriden methods from jgraphx
*/
}
/**
- * Re-associate fields with the new instance.
- *
- * @return a new clone instance
- * @throws CloneNotSupportedException
- * never
- * @see com.mxgraph.model.mxCell#clone()
- */
- @Override
- public Object clone() throws CloneNotSupportedException {
- BasicBlock clone = (BasicBlock) super.clone();
-
- /* Reinstall the PropertyChangeSupport and all of it listeners */
- clone.parametersPCS = new PropertyChangeSupport(clone);
- PropertyChangeSupport pcs = getParametersPCS();
- for (PropertyChangeListener iter : pcs.getPropertyChangeListeners()) {
- clone.parametersPCS.addPropertyChangeListener(iter);
- }
-
- return clone;
- }
-
- /**
* {@inheritDoc}
*
* Sync the specific child {@link EditFormatAction#HASH_IDENTIFIER}
@Override
public String toString() {
final StringBuilder str = new StringBuilder();
- str.append(getInterfaceFunctionName());
+
+ JavaController controller = new JavaController();
+
+ String[] interfaceFunction = new String[1];
+ controller.getObjectProperty(uid, Kind.BLOCK, ObjectProperties.INTERFACE_FUNCTION, interfaceFunction);
+
+ str.append(interfaceFunction[0]);
str.append("\n");
for (Object c : children) {
str.append(c);
return str.toString();
}
}
-// CSON: ClassDataAbstractionCoupling
-// CSON: ClassFanOutComplexity
package org.scilab.modules.xcos.block;
+import java.lang.reflect.InvocationTargetException;
+
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.Kind;
+import org.scilab.modules.xcos.ObjectProperties;
import org.scilab.modules.xcos.block.io.EventInBlock;
import org.scilab.modules.xcos.block.io.EventOutBlock;
import org.scilab.modules.xcos.block.io.ExplicitInBlock;
*/
public static enum BlockInterFunction {
/** @see TextBlock */
- TEXT_f(new TextBlock()),
+ TEXT_f(TextBlock.class),
/** @see SuperBlock */
- DSUPER(new SuperBlock(true)),
+ DSUPER(SuperBlock.class),
/** @see SuperBlock */
- SUPER_f(new SuperBlock()),
+ SUPER_f(SuperBlock.class),
/** @see AfficheBlock */
- AFFICH_m(new AfficheBlock()),
+ AFFICH_m(AfficheBlock.class),
/** @see AfficheBlock */
- AFFICH_f(AFFICH_m.getSharedInstance()),
+ AFFICH_f(AfficheBlock.class),
/** @see ExplicitInBlock */
- IN_f(new ExplicitInBlock()),
+ IN_f(ExplicitInBlock.class),
/** @see ExplicitOutBlock */
- OUT_f(new ExplicitOutBlock()),
+ OUT_f(ExplicitOutBlock.class),
/** @see ImplicitInBlock */
- INIMPL_f(new ImplicitInBlock()),
+ INIMPL_f(ImplicitInBlock.class),
/** @see ImplicitOutBlock */
- OUTIMPL_f(new ImplicitOutBlock()),
+ OUTIMPL_f(ImplicitOutBlock.class),
/** @see EventInBlock */
- CLKINV_f(new EventInBlock()),
+ CLKINV_f(EventInBlock.class),
/** @see EventOutBlock */
- CLKOUTV_f(new EventOutBlock()),
+ CLKOUTV_f(EventOutBlock.class),
/** @see EventOutBlock */
- CLKOUT_f(CLKOUTV_f.getSharedInstance()),
+ CLKOUT_f(EventOutBlock.class),
/** @see SplitBlock */
- SPLIT_f(new SplitBlock()),
+ SPLIT_f(SplitBlock.class),
/** @see SplitBlock */
- IMPSPLIT_f(SPLIT_f.getSharedInstance()),
+ IMPSPLIT_f(SplitBlock.class),
/** @see SplitBlock */
- CLKSPLIT_f(SPLIT_f.getSharedInstance()),
+ CLKSPLIT_f(SplitBlock.class),
/** @see GroundBlock */
- Ground(new GroundBlock()),
+ Ground(GroundBlock.class),
/** @see VoltageSensorBlock */
- VoltageSensor(new VoltageSensorBlock()),
+ VoltageSensor(VoltageSensorBlock.class),
/** @see RoundBlock */
- SUM_f(new RoundBlock("SUM_f")),
+ SUM_f(RoundBlock.class),
/** @see RoundBlock */
- PROD_f(new RoundBlock("PROD_f")),
+ PROD_f(RoundBlock.class),
/** @see RoundBlock */
- CLKSOM_f(new RoundBlock("CLKSOM_f")),
+ CLKSOM_f(RoundBlock.class),
/** @see RoundBlock */
- CLKSOMV_f(new RoundBlock("CLKSOMV_f")),
+ CLKSOMV_f(RoundBlock.class),
/** @see BigSom */
- BIGSOM_f(new BigSom()),
+ BIGSOM_f(BigSom.class),
/** @see Summation */
- SUMMATION(new Summation()),
+ SUMMATION(Summation.class),
/** @see Product */
- PRODUCT(new Product());
+ PRODUCT(Product.class);
- private BasicBlock block;
+ private final Class<? extends BasicBlock> klass;
/**
* Default constructor
* @param block
* The reference instance
*/
- private BlockInterFunction(BasicBlock block) {
- this.block = block;
+ private BlockInterFunction(Class<? extends BasicBlock> klass) {
+ this.klass = klass;
}
/**
- * Create a block instance
- *
- * @return The new block instance
+ * @return the class to instantiate
*/
- private BasicBlock createInstance() {
- BasicBlock clone = null;
-
- if (block != null) {
- clone = (BasicBlock) BlockFactory.createClone(block);
- }
- return clone;
- }
-
- /**
- * Get the reference shared block instance for this BlockInterFunction.
- *
- * @return The shared block instance
- */
- public BasicBlock getSharedInstance() {
- return block;
+ public Class<? extends BasicBlock> getKlass() {
+ return klass;
}
}
}
/**
- * Instantiate a new block with the specified interface function name.
+ * Instantiate a new block with the specified UID value.
*
- * @param label
- * The interface function name.
+ * @param uid
+ * The associated UID value
* @return A new instance of a block.
*/
- public static BasicBlock createBlock(String label) {
+ public static BasicBlock createBlock(long uid) {
BasicBlock block = null;
+ JavaController controller = new JavaController();
+ String[] interfaceFunction = new String[1];
+ controller.getObjectProperty(uid, Kind.BLOCK, ObjectProperties.INTERFACE_FUNCTION, interfaceFunction);
+
for (BlockInterFunction func : BlockInterFunction.values()) {
- if (label.compareTo(func.name()) == 0) {
- block = func.createInstance();
+ if (func.name().equals(interfaceFunction)) {
+ block = createBlock(func, uid);
break;
}
}
// Not specific block
if (block == null) {
- block = new BasicBlock(label);
+ block = new BasicBlock(uid);
}
return block;
* @return A new instance of a block.
*/
public static BasicBlock createBlock(BlockInterFunction func) {
- return func.createInstance();
+ JavaController controller = new JavaController();
+
+ long uid = controller.createObject(Kind.BLOCK);
+ return createBlock(func, uid);
+ }
+
+ /**
+ * Instantiate a new block with the specified interface function and uid.
+ *
+ * @param func the interface function
+ * @param uid the allocated uid
+ * @return A new instance of a block.
+ */
+ public static BasicBlock createBlock(BlockInterFunction func, long uid) {
+ BasicBlock block = null;
+ try {
+ block = func.getKlass().getConstructor(Long.TYPE).newInstance(uid);
+ } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
+ // Something goes wrong, print it.
+ e.printStackTrace();
+ }
+
+ return block;
}
/**
* @return the clone
*/
public static Object createClone(BasicBlock block) {
+ JavaController controller = new JavaController();
+
try {
+ // FIXME implement the MVC part
+ // long uid = controller.cloneObject(block.getUID(), true);
+
BasicBlock clone = (BasicBlock) block.clone();
/* Clone children */
import java.util.logging.Logger;
-import org.scilab.modules.types.ScilabDouble;
-import org.scilab.modules.types.ScilabList;
import org.scilab.modules.xcos.port.BasicPort;
-import org.scilab.modules.xcos.port.BasicPort.Type;
-import org.scilab.modules.xcos.port.command.CommandPort;
-import org.scilab.modules.xcos.port.control.ControlPort;
-import org.scilab.modules.xcos.port.input.ExplicitInputPort;
-import org.scilab.modules.xcos.port.input.ImplicitInputPort;
-import org.scilab.modules.xcos.port.output.ExplicitOutputPort;
-import org.scilab.modules.xcos.port.output.ImplicitOutputPort;
import com.mxgraph.model.mxGeometry;
import com.mxgraph.model.mxICell;
/** The default color value */
public static final int DEFAULT_COLOR = 7;
- private static final long serialVersionUID = 5817243367840540106L;
-
/**
* Constructor
*/
- public SplitBlock() {
- super();
- }
-
- /**
- * Add connection port depending on the type of the source.
- *
- * @param source
- * the type of the split
- */
- public void addConnection(BasicPort source) {
- if (source.getType() == Type.EXPLICIT) {
- addPort(new ExplicitInputPort());
- addPort(new ExplicitOutputPort());
- addPort(new ExplicitOutputPort());
-
- setInterfaceFunctionName("SPLIT_f");
- } else if (source.getType() == Type.IMPLICIT) {
- addPort(new ImplicitInputPort());
- addPort(new ImplicitOutputPort());
- addPort(new ImplicitOutputPort());
-
- setInterfaceFunctionName("IMPSPLIT_f");
- } else {
- addPort(new ControlPort());
- addPort(new CommandPort());
- addPort(new CommandPort());
-
- setInterfaceFunctionName("CLKSPLIT_f");
- }
-
- getChildAt(0).setVisible(false);
- getChildAt(1).setVisible(false);
- getChildAt(2).setVisible(false);
- }
-
- /**
- * Initialize the block with the default values
- */
- @Override
- protected void setDefaultValues() {
- super.setDefaultValues();
- setInterfaceFunctionName("SPLIT_f");
- setStyle(getInterfaceFunctionName());
- setSimulationFunctionName("lsplit");
- setRealParameters(new ScilabDouble());
- setIntegerParameters(new ScilabDouble());
- setObjectsParameters(new ScilabList());
- setExprs(new ScilabDouble());
+ public SplitBlock(long uid) {
+ super(uid);
}
/**
package org.scilab.modules.xcos.block;
import java.io.IOException;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
-import org.scilab.modules.commons.xml.ScilabDocumentBuilderFactory;
import org.scilab.modules.graph.ScilabGraph;
import org.scilab.modules.gui.contextmenu.ContextMenu;
import org.scilab.modules.gui.menu.Menu;
import org.scilab.modules.gui.menu.ScilabMenu;
-import org.scilab.modules.types.ScilabDouble;
-import org.scilab.modules.types.ScilabList;
-import org.scilab.modules.types.ScilabMList;
-import org.scilab.modules.types.ScilabType;
-import org.scilab.modules.xcos.Xcos;
-import org.scilab.modules.xcos.XcosTab;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.Kind;
+import org.scilab.modules.xcos.ObjectProperties;
+import org.scilab.modules.xcos.VectorOfInt;
import org.scilab.modules.xcos.block.actions.CodeGenerationAction;
import org.scilab.modules.xcos.block.actions.SuperblockMaskCreateAction;
import org.scilab.modules.xcos.block.actions.SuperblockMaskCustomizeAction;
import org.scilab.modules.xcos.block.actions.SuperblockMaskRemoveAction;
-import org.scilab.modules.xcos.block.io.ContextUpdate.IOBlocks;
-import org.scilab.modules.xcos.graph.PaletteDiagram;
-import org.scilab.modules.xcos.graph.SuperBlockDiagram;
-import org.scilab.modules.xcos.graph.XcosDiagram;
-import org.scilab.modules.xcos.graph.swing.GraphComponent;
-import org.scilab.modules.xcos.io.codec.XcosCodec;
-import org.scilab.modules.xcos.io.scicos.DiagramElement;
-import org.scilab.modules.xcos.io.scicos.ScicosFormatException;
-import org.scilab.modules.xcos.port.BasicPort;
import org.scilab.modules.xcos.utils.FileUtils;
-import org.scilab.modules.xcos.utils.XcosConstants;
-import org.scilab.modules.xcos.utils.XcosEvent;
import org.scilab.modules.xcos.utils.XcosMessages;
-import org.w3c.dom.Document;
import org.w3c.dom.Node;
-import com.mxgraph.model.mxICell;
-import com.mxgraph.util.mxEvent;
-import com.mxgraph.util.mxEventObject;
-
/**
* A SuperBlock contains an entire diagram on it. Thus it can be easily
* customized by the user.
*/
private static final String MASKED_INTERFUNCTION_NAME = "DSUPER";
- private SuperBlockDiagram child;
-
/**
* Constructor
*/
- public SuperBlock() {
- super();
- }
+ public SuperBlock(long uid, String label, boolean masked) {
+ super(uid);
- /**
- * @param label
- * block label
- */
- protected SuperBlock(String label) {
- this();
setValue(label);
- }
-
- /**
- * @param masked
- * masked super block
- */
- protected SuperBlock(boolean masked) {
- this();
if (masked) {
mask();
}
}
- /**
- * @param label
- * block label
- * @param masked
- * masked super block
- */
- protected SuperBlock(String label, boolean masked) {
- this(label);
- if (masked) {
- mask();
- }
- }
-
- /**
- * Initialize the block with the default values
- */
- @Override
- protected void setDefaultValues() {
- super.setDefaultValues();
- setInterfaceFunctionName(INTERFUNCTION_NAME);
- setSimulationFunctionName(SIMULATION_NAME);
- setRealParameters(new ScilabMList());
- setIntegerParameters(new ScilabDouble());
- setObjectsParameters(new ScilabList());
- setExprs(new ScilabDouble());
- setBlockType("h");
- setNbZerosCrossing(new ScilabDouble(0));
- setNmode(new ScilabDouble(0));
- }
-
- @Override
- public ScilabType getRealParameters() {
- if (child == null) {
- return super.getRealParameters();
- }
-
- /*
- * Encode the children as a new rpar.
- */
- final ScilabType rpar = new DiagramElement().encode(child);
- super.setRealParameters(rpar);
- hasAValidRpar = true;
-
- return super.getRealParameters();
- }
-
- /**
- * openBlockSettings this method is called when a double click occurred on a
- * super block
- *
- * @param context
- * parent diagram context
- * @see BasicBlock#openBlockSettings(String[])
- */
- @Override
- public void openBlockSettings(String[] context) {
-
- // prevent to open twice
- if (isLocked()) {
- return;
- }
-
- /*
- * Do nothing when something happen on the Palette
- */
- if (getParentDiagram() instanceof PaletteDiagram) {
- return;
- }
-
- /*
- * Specific case when we want to generate code.
- */
- if (getChild() == null && getSimulationFunctionType().compareTo(SimulationFunctionType.DEFAULT) != 0) {
- return;
- }
-
- /*
- * When the block is masked it perform actions like any other blocks.
- */
- if (isMasked()) {
- super.openBlockSettings(context);
- return;
- }
-
- try {
- // Lock the block because we are really performing actions
- setLocked(true);
-
- /*
- * Compatibility with older diagrams.
- *
- * Before Scilab 5.2.2, saved diagrams don't contains XML children
- * but use a pseudo scs_m structure instead.
- *
- * In this case child was null and we need to reconstruct child
- * diagram from scs_m.
- */
- if (getChild() == null || getChild().getChildVertices(getChild().getDefaultParent()).length == 0) {
- child = null;
- createChildDiagram();
- } else {
- // reassociate (useful on clone and load operation)
- getChild().setContainer(this);
- getChild().setComponent(new GraphComponent(getChild()));
-
- getChild().initComponent();
- getChild().installStylesheet();
-
- getChild().installListeners();
- getChild().installSuperBlockListeners();
- }
-
- /*
- * Construct the view or set it visible.
- */
- if (XcosTab.get(getChild()) == null) {
- XcosTab.restore(getChild());
- } else {
- XcosTab.get(getChild()).setCurrent();
- }
-
- getChild().setModifiedNonRecursively(false);
-
- getChild().getAsComponent().validateGraph();
- getChild().fireEvent(new mxEventObject(mxEvent.ROOT));
- getChild().getView().invalidate();
-
- /*
- * Update the cells from the context values.
- */
- getChild().updateCellsContext();
- } finally {
- setLocked(false);
- }
+ public SuperBlock(long uid) {
+ this(uid, INTERFUNCTION_NAME, false);
}
/**
public void openContextMenu(ScilabGraph graph) {
ContextMenu menu = null;
- if (getParentDiagram() instanceof PaletteDiagram) {
- menu = createPaletteContextMenu(graph);
- } else {
- menu = createContextMenu(graph);
- menu.getAsSimpleContextMenu().addSeparator();
- menu.add(CodeGenerationAction.createMenu(graph));
+ menu = createContextMenu(graph);
+ menu.getAsSimpleContextMenu().addSeparator();
+ menu.add(CodeGenerationAction.createMenu(graph));
- Menu maskMenu = ScilabMenu.createMenu();
- maskMenu.setText(XcosMessages.SUPERBLOCK_MASK);
+ Menu maskMenu = ScilabMenu.createMenu();
+ maskMenu.setText(XcosMessages.SUPERBLOCK_MASK);
- if (isMasked()) {
- maskMenu.add(SuperblockMaskRemoveAction.createMenu(graph));
- menu.add(maskMenu);
- } else {
- maskMenu.add(SuperblockMaskCreateAction.createMenu(graph));
- }
- maskMenu.add(SuperblockMaskCustomizeAction.createMenu(graph));
+ if (isMasked()) {
+ maskMenu.add(SuperblockMaskRemoveAction.createMenu(graph));
menu.add(maskMenu);
-
- }
- menu.setVisible(true);
- }
-
- /**
- * @return status
- */
- public boolean createChildDiagram() {
- return createChildDiagram(false);
- }
-
- /**
- * @param generatedUID
- * does we need to generated a new unique ID
- * @return status
- */
- public boolean createChildDiagram(boolean generatedUID) {
- if (child == null) {
- final ScilabType rpar = getRealParameters();
-
- final DiagramElement element = new DiagramElement();
- if (!element.canDecode(rpar)) {
- return false;
- }
-
- child = new SuperBlockDiagram(this);
- child.installListeners();
-
- try {
- element.decode(rpar, child, false);
- } catch (ScicosFormatException e) {
- Logger.getLogger(SuperBlock.class.getName()).severe(e.toString());
- return false;
- }
-
- child.installSuperBlockListeners();
-
- final XcosDiagram parent = Xcos.findParent(this);
- if (parent != null) {
- Xcos.getInstance().addDiagram(parent.getSavedFile(), child);
- }
} else {
- return false;
- }
-
- return true;
- }
-
- /**
- * @return diagram
- */
- public SuperBlockDiagram getChild() {
- return child;
- }
-
- /**
- * @param child
- * update diagram
- */
- public void setChild(SuperBlockDiagram child) {
- this.child = child;
- }
-
- /**
- * Function that insert one port on the concerned superblock
- * and gives it the right order.
- *
- * @param order
- * @param basicblock
- */
- private void insertOnePort(int order, BasicBlock basicblock) {
- try {
- for (IOBlocks b : IOBlocks.values()) {
- if (basicblock.getClass().equals(b.getReferencedClass())) {
- BasicPort port;
- port = b.getReferencedPortClass().newInstance();
- port.setOrdering(order);
- insert(port);
- }
- }
- } catch (InstantiationException e) {
- Logger.getLogger(SuperBlock.class.getName()).severe(e.toString());
- } catch (IllegalAccessException e) {
- Logger.getLogger(SuperBlock.class.getName()).severe(e.toString());
- } catch (Exception e) {
- Logger.getLogger(SuperBlock.class.getName()).severe(e.toString());
- }
- }
-
- /**
- * Function that remove one port on the concerned superblock
- *
- * @param order
- * @param basicport
- * @param basicblock
- * @return
- */
- private boolean removeOnePort(int order, BasicPort basicport, BasicBlock basicblock) {
- boolean port_deleted = false;
-
- for (IOBlocks b : IOBlocks.values()) {
- if (basicport.getClass().equals(b.getReferencedPortClass())) {
- if (!basicblock.getClass().equals(b.getReferencedClass())) {
- // delete the port
- removePort(basicport);
- port_deleted = true;
- }
- }
- }
-
- return port_deleted;
- }
-
- /**
- *
- * @param basicport
- */
- private void removeOnePort(BasicPort basicport) {
- // delete the port
- removePort(basicport);
- }
-
- /**
- * Function that returns a hashtable of IOBlocks contained in the superdiagram
- * depending on their direction.
- *
- * @param blockMap
- * a map of blocks
- * @return the hashtable
- */
- private Hashtable<String, List<? extends mxICell>> extractContextBlocks() {
- // get a map of all the IOBlocks of the superdiagram
- final Map<IOBlocks, List<BasicBlock>> blocksMap = IOBlocks.getAllBlocks(this);
-
- // create a map of all the blocks of the superdiagram depending on their type
- Hashtable<String, List<? extends mxICell>> context_block = new Hashtable<String, List<? extends mxICell>> ();
-
- if (!context_block.containsKey(XcosDiagram.IN)) {
- List<BasicBlock> cell_list = blocksMap.get(IOBlocks.ExplicitInBlock);
- cell_list.addAll(blocksMap.get(IOBlocks.ImplicitInBlock));
- context_block.put(XcosDiagram.IN, cell_list);
- }
- if (!context_block.containsKey(XcosDiagram.OUT)) {
- List<BasicBlock> cell_list = blocksMap.get(IOBlocks.ExplicitOutBlock);
- cell_list.addAll(blocksMap.get(IOBlocks.ImplicitOutBlock));
- context_block.put(XcosDiagram.OUT, cell_list);
- }
- if (!context_block.containsKey(XcosDiagram.EIN)) {
- List<BasicBlock> cell_list = blocksMap.get(IOBlocks.EventInBlock);
- context_block.put(XcosDiagram.EIN, cell_list);
- }
- if (!context_block.containsKey(XcosDiagram.EOUT)) {
- List<BasicBlock> cell_list = blocksMap.get(IOBlocks.EventOutBlock);
- context_block.put(XcosDiagram.EOUT, cell_list);
- }
-
- return context_block;
- }
-
- /**
- * Function that returns a hashtable of the superblock ports
- * depending on their direction.
- *
- * @param portsMap
- * a map of ports
- * @return the hashtable
- */
- private Hashtable<String, List<? extends mxICell>> extractContextPorts() {
- // get a map of all the ports of the superblock
- final Map<IOBlocks, List<mxICell>> portsMap = IOBlocks.getAllPorts(this);
-
- // create a map of all the ports of the superblock depending on their type
- Hashtable<String, List<? extends mxICell>> context_port = new Hashtable<String, List<? extends mxICell>> ();
-
- if (!context_port.containsKey(XcosDiagram.IN)) {
- List<mxICell> cell_list = portsMap.get(IOBlocks.ExplicitInBlock);
- cell_list.addAll(portsMap.get(IOBlocks.ImplicitInBlock));
- context_port.put(XcosDiagram.IN, cell_list);
- }
- if (!context_port.containsKey(XcosDiagram.OUT)) {
- List<mxICell> cell_list = portsMap.get(IOBlocks.ExplicitOutBlock);
- cell_list.addAll(portsMap.get(IOBlocks.ImplicitOutBlock));
- context_port.put(XcosDiagram.OUT, cell_list);
- }
- if (!context_port.containsKey(XcosDiagram.EIN)) {
- List<mxICell> cell_list = portsMap.get(IOBlocks.EventInBlock);
- context_port.put(XcosDiagram.EIN, cell_list);
- }
- if (!context_port.containsKey(XcosDiagram.EOUT)) {
- List<mxICell> cell_list = portsMap.get(IOBlocks.EventOutBlock);
- context_port.put(XcosDiagram.EOUT, cell_list);
+ maskMenu.add(SuperblockMaskCreateAction.createMenu(graph));
}
+ maskMenu.add(SuperblockMaskCustomizeAction.createMenu(graph));
+ menu.add(maskMenu);
- return context_port;
- }
-
- /**
- * Function that add a port to a superblock. The function should be called only when
- * the number of superdiagram blocks is higher than the superblock port number.
- *
- * @param key
- * direction of the block ports
- * @param context_block
- * the list of blocks
- * @param context_port
- * the list of ports
- */
- private void addPorts(String key, Hashtable<String, List<? extends mxICell>> context_block, Map<String, List<? extends mxICell>> context_port) {
- // iterate on the superdiagram blocks
- for (mxICell cell : context_block.get(key)) {
- if (cell instanceof BasicBlock) {
- BasicBlock basicblock = (BasicBlock) cell;
- int order = (int) ((ScilabDouble) basicblock.getIntegerParameters()).getRealPart()[0][0];
-
- // get the new added block if found
- List<? extends mxICell> port_list = context_port.get(key);
- boolean port_found = false;
- for (mxICell port : port_list) {
- if (port instanceof BasicPort) {
- BasicPort basicport = (BasicPort) port;
- if (order == basicport.getOrdering()) {
- port_found = true;
- break;
- }
- }
- }
-
- if (port_found == false) {
- // add the port on the superblock
- insertOnePort(order, basicblock);
- }
- }
- }
- }
-
- /**
- * Function that remove a port to a superblock. The function should be called only when
- * the number of superdiagram blocks is less than the superblock port number.
- *
- * @param key
- * direction of the block ports
- * @param context_block
- * the list of blocks
- * @param context_port
- * the list of ports
- */
- private void removePorts(String key, Hashtable<String, List<? extends mxICell>> context_block, Map<String, List<? extends mxICell>> context_port) {
- // iterate on the superblock ports
- for (mxICell cell : context_port.get(key)) {
- if (cell instanceof BasicPort) {
- BasicPort basicport = (BasicPort) cell;
- int order = basicport.getOrdering();
-
- // get the port to remove
- List<? extends mxICell> block_list = context_block.get(key);
- boolean block_found = false;
- for (mxICell block : block_list) {
- if (block instanceof BasicBlock) {
- BasicBlock basicblock = (BasicBlock) block;
- int block_order = (int) ((ScilabDouble) basicblock.getIntegerParameters()).getRealPart()[0][0];
- if (order == block_order) {
- block_found = true;
- break;
- }
- }
- }
-
- if (block_found == false) {
- // delete the port
- removeOnePort(basicport);
- }
- }
- }
- }
-
- /**
- * Function that remove dead ports from the superblock. A dead port is a port which has not
- * a corresponding superdiagram IOBlock
- *
- * @param key
- * direction of the block ports
- * @param context_block
- * the list of blocks
- * @param context_port
- * the list of ports
- */
- private void removeDeadPorts(String key, Hashtable<String, List<? extends mxICell>> context_block, Map<String, List<? extends mxICell>> context_port) {
- // first remove dead ports
- for (mxICell cell : context_port.get(key)) {
- if (cell instanceof BasicPort) {
- BasicPort basicport = (BasicPort) cell;
- int order = basicport.getOrdering();
-
- // get the port to remove
- List<? extends mxICell> block_list = context_block.get(key);
- boolean block_found = false;
- for (mxICell block : block_list) {
- if (block instanceof BasicBlock) {
- BasicBlock basicblock = (BasicBlock) block;
- int block_order = (int) ((ScilabDouble) basicblock.getIntegerParameters()).getRealPart()[0][0];
- if (order == block_order) {
- block_found = true;
- break;
- }
- }
- }
-
- if (block_found == false) {
- // delete the port
- removeOnePort(basicport);
- }
- }
- }
- }
-
- /**
- * Function that replace a port of a superblock
- * if its numbering has changed
- *
- * @param key
- * direction of the block ports
- * @param context_block
- * the list of blocks
- * @param context_port
- * the list of ports
- */
- private void replacePort(String key, Hashtable<String, List<? extends mxICell>> context_block, Map<String, List<? extends mxICell>> context_port) {
- // iterate on the superdiagram blocks
- for (mxICell cell : context_block.get(key)) {
- if (cell instanceof BasicBlock) {
- BasicBlock basicblock = (BasicBlock) cell;
- int order = (int) ((ScilabDouble) basicblock.getIntegerParameters()).getRealPart()[0][0];
-
- // verify superblock port coherence
- List<? extends mxICell> port_list = context_port.get(key);
- BasicPort basicport = null;
- boolean port_found = false;
- for (mxICell port : port_list) {
- if (port instanceof BasicPort) {
- basicport = (BasicPort) port;
- if (order == basicport.getOrdering()) {
- port_found = true;
- break;
- }
- }
- }
-
- if (port_found == true) {
- boolean port_deleted = false;
- port_deleted = removeOnePort(order, basicport, basicblock);
-
- // add the port on the superblock if deleted
- if (port_deleted == true) {
- insertOnePort(order, basicblock);
- }
- } else {
- insertOnePort(order, basicblock);
- }
- }
- }
- }
-
- /**
- * Function that updates super block ports in parent diagram
- */
- public void updateExportedPort() {
- if (child == null) {
- return;
- }
- if (getParentDiagram() == null) {
- setParentDiagram(Xcos.findParent(this));
- }
-
- // extracting blocks from the superdiagram
- Hashtable<String, List<? extends mxICell>> context_block = extractContextBlocks();
- // extracting ports from the superblock
- Hashtable<String, List<? extends mxICell>> context_port = extractContextPorts();
-
- for (String key : context_block.keySet()) {
- if (context_block.get(key).size() > context_port.get(key).size()) {
- // adding ports of the superblock
- addPorts(key, context_block, context_port);
- } else if (context_block.get(key).size() < context_port.get(key).size()) {
- // removing ports of the superblock
- removePorts(key, context_block, context_port);
- } else {
- // reordering ports of the superblock
- removeDeadPorts(key, context_block, context_port);
- replacePort(key, context_block, context_port);
- }
- }
-
- getParentDiagram().fireEvent(new mxEventObject(XcosEvent.SUPER_BLOCK_UPDATED, XcosConstants.EVENT_BLOCK_UPDATED, this));
+ menu.setVisible(true);
}
/**
* Mask the SuperBlock
*/
public void mask() {
- setInterfaceFunctionName(MASKED_INTERFUNCTION_NAME);
- setSimulationFunctionName(MASKED_SIMULATION_NAME);
- setIntegerParameters(new ScilabDouble(1));
+ JavaController controller = new JavaController();
+
+ controller.setObjectProperty(getUID(), Kind.BLOCK, ObjectProperties.INTERFACE_FUNCTION, MASKED_INTERFUNCTION_NAME);
+ controller.setObjectProperty(getUID(), Kind.BLOCK, ObjectProperties.SIM_FUNCTION_NAME, MASKED_SIMULATION_NAME);
+
+ VectorOfInt ipar = new VectorOfInt(1);
+ ipar.set(0, 1);
+ controller.setObjectProperty(getUID(), Kind.BLOCK, ObjectProperties.IPAR, ipar);
}
/**
* Unmask the SuperBlock
*/
public void unmask() {
- setInterfaceFunctionName(INTERFUNCTION_NAME);
- setSimulationFunctionName(SIMULATION_NAME);
- setIntegerParameters(new ScilabDouble());
+ JavaController controller = new JavaController();
+
+ controller.setObjectProperty(getUID(), Kind.BLOCK, ObjectProperties.INTERFACE_FUNCTION, INTERFUNCTION_NAME);
+ controller.setObjectProperty(getUID(), Kind.BLOCK, ObjectProperties.SIM_FUNCTION_NAME, SIMULATION_NAME);
}
/**
* @return True is the SuperBlock is masked, false otherwise
*/
public boolean isMasked() {
- return getInterfaceFunctionName().compareTo(INTERFUNCTION_NAME) != 0;
+ JavaController controller = new JavaController();
+
+ String[] interfaceFunction = new String[1];
+ controller.getObjectProperty(getUID(), Kind.BLOCK, ObjectProperties.INTERFACE_FUNCTION, interfaceFunction);
+
+ return !INTERFUNCTION_NAME.equals(interfaceFunction[0]);
}
/**
return;
}
- if (getChild() != null) {
- getChild().setTitle(FileUtils.toValidCIdentifier(value.toString()));
- setRealParameters(new DiagramElement().encode(getChild()));
- }
- }
-
- /**
- * Clone the child safely.
- *
- * @return a new clone instance
- * @throws CloneNotSupportedException
- * never
- * @see org.scilab.modules.xcos.block.BasicBlock#clone()
- */
- @Override
- public Object clone() throws CloneNotSupportedException {
- SuperBlock clone = (SuperBlock) super.clone();
-
- // clone the diagram
- if (child != null) {
- clone.child = (SuperBlockDiagram) child.clone();
- clone.child.setContainer(clone);
- }
-
- return clone;
-
+ JavaController controller = new JavaController();
+ controller.setObjectProperty(getUID(), Kind.BLOCK, ObjectProperties.TITLE, FileUtils.toValidCIdentifier(value.toString()));
}
/*
*/
/**
- * Encode the block as xml
- *
- * @param out
- * the output stream
- * @throws IOException
- * on error
- * @throws ParserConfigurationException on error
- */
- private void writeObject(java.io.ObjectOutputStream out) throws IOException, ParserConfigurationException {
- final XcosCodec codec = new XcosCodec();
- out.writeObject(codec.encode(this));
- }
-
- /**
* Decode the block as xml
*
* @param in
*/
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException, ParserConfigurationException {
final Node input = (Node) in.readObject();
- final XcosCodec codec = new XcosCodec(input.getOwnerDocument());
- codec.setElementIdAttributes();
- codec.decode(input, this);
-
- /*
- * Specific post serialization things
- */
- if (this.child == null) {
- this.child = new SuperBlockDiagram(this);
- this.child.installListeners();
- } else {
- this.child.setContainer(this);
- }
- this.child.installSuperBlockListeners();
+ // FIXME: clone the MVC data
}
}
// CSON: ClassDataAbstractionCoupling
import java.util.Map;
import org.scilab.modules.graph.actions.base.DefaultAction;
-import org.scilab.modules.graph.utils.Font;
-import org.scilab.modules.graph.utils.StyleMap;
import org.scilab.modules.gui.menu.Menu;
-import org.scilab.modules.types.ScilabDouble;
-import org.scilab.modules.types.ScilabString;
-import org.scilab.modules.types.ScilabType;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.Kind;
+import org.scilab.modules.xcos.ObjectProperties;
import org.scilab.modules.xcos.block.actions.BlockParametersAction;
import org.scilab.modules.xcos.block.actions.RegionToSuperblockAction;
import org.scilab.modules.xcos.utils.XcosMessages;
-import static org.scilab.modules.xcos.io.scicos.AbstractElement.getIndexes;
-import static org.scilab.modules.xcos.io.scicos.AbstractElement.canGet;
-
-import com.mxgraph.util.mxConstants;
-
/**
* A textblock is used to annotate diagrams.
*/
@SuppressWarnings(value = { "serial" })
public final class TextBlock extends BasicBlock {
- private static final String INTERFUNCTION_NAME = "TEXT_f";
-
/**
* Default constructor
*/
- public TextBlock() {
- super();
- }
-
- /**
- * Initialize the block with the default values
- */
- @Override
- protected void setDefaultValues() {
- super.setDefaultValues();
- setInterfaceFunctionName(INTERFUNCTION_NAME);
- setStyle(INTERFUNCTION_NAME);
+ public TextBlock(long uid) {
+ super(uid);
setValue(XcosMessages.DOTS);
}
/**
- * @return the fontNumber
- */
- private Font getFont() {
- final ScilabString exprs = getLocalExprs();
- int number;
-
- final boolean isColumnDominant = exprs.getHeight() >= exprs.getWidth();
- final int[] indexes = getIndexes(1, isColumnDominant);
- if (canGet(exprs, indexes)) {
- number = Integer.parseInt(exprs.getData()[indexes[0]][indexes[1]]);
- } else {
- number = 0;
- }
- return Font.getFont(number);
- }
-
- /**
- * @return the fontSize
- */
- private int getFontSize() {
- final ScilabString exprs = getLocalExprs();
- int number;
-
- final boolean isColumnDominant = exprs.getHeight() >= exprs.getWidth();
- final int[] indexes = getIndexes(2, isColumnDominant);
- if (canGet(exprs, indexes)) {
- number = Integer.parseInt(exprs.getData()[indexes[0]][indexes[1]]);
- } else {
- number = 0;
- }
- return Font.getSize(number);
- }
-
- /**
- * Format exprs as a Scilab valid one
- */
- @Override
- public ScilabType getExprs() {
- final String[][] data = new String[][] { new String[] { getValue().toString(), "2", "1" } };
- return new ScilabString(data);
- }
-
- /**
- * Exprs accessor
- */
- private ScilabString getLocalExprs() {
- return (ScilabString) super.getExprs();
- }
-
- @Override
- public ScilabType getRealParameters() {
- return new ScilabString(getValue().toString());
- }
-
- @Override
- public ScilabType getIntegerParameters() {
- final double[][] data = new double[][] { new double[] { 2, 1 } };
- return new ScilabDouble(data);
- }
-
- /**
- * Apply style on setExprs
- *
- * @param exprs
- * the expression to be parsed
- */
- @Override
- public void setExprs(ScilabType exprs) {
- super.setExprs(exprs);
-
- final StyleMap map = new StyleMap(getStyle());
- map.put(mxConstants.STYLE_FONTFAMILY, getFont().getName());
- map.put(mxConstants.STYLE_FONTSIZE, Integer.toString(getFontSize()));
- setStyle(map.toString());
-
- setValue(getLocalExprs().getData()[0][0]);
- }
-
- /**
- * Disabling BlockSettings action
- *
- * @param context
- * the current context
- */
- @Override
- public void openBlockSettings(String[] context) {
- // NOTHING TO BE DONE
- }
-
- /**
- * Disabling BlockSettings action
- *
- * @param modifiedBlock
- * the updated block
- */
- @Override
- public void updateBlockSettings(BasicBlock modifiedBlock) {
- // NOTHING TO BE DONE
- }
-
- /**
* Customize menu
*
* @param menuList
menuList.get(BlockParametersAction.class).setEnabled(false);
menuList.get(RegionToSuperblockAction.class).setEnabled(false);
}
+
+ @Override
+ public void setValue(Object value) {
+ if (value != null) {
+ JavaController controller = new JavaController();
+ controller.setObjectProperty(getUID(), Kind.ANNOTATION, ObjectProperties.DESCRIPTION, value.toString());
+ }
+
+ super.setValue(value);
+ }
}
import org.scilab.modules.graph.ScilabGraph;
import org.scilab.modules.graph.actions.base.VertexSelectionDependantAction;
import org.scilab.modules.gui.menuitem.MenuItem;
+import org.scilab.modules.xcos.JavaController;
+import org.scilab.modules.xcos.Kind;
+import org.scilab.modules.xcos.ObjectProperties;
import org.scilab.modules.xcos.block.BasicBlock;
import org.scilab.modules.xcos.graph.XcosDiagram;
import org.scilab.modules.xcos.utils.XcosDialogs;
Object selected = graph.getSelectionCell();
if (selected instanceof BasicBlock) {
try {
- ScilabInterpreterManagement.asynchronousScilabExec(null, "help", ((BasicBlock) selected).getInterfaceFunctionName());
+ JavaController controller = new JavaController();
+
+ String[] interfaceFunction = new String[1];
+ controller.getObjectProperty(((BasicBlock) selected).getUID(), Kind.BLOCK, ObjectProperties.INTERFACE_FUNCTION, interfaceFunction);
+
+ ScilabInterpreterManagement.asynchronousScilabExec(null, "help", interfaceFunction[0]);
} catch (InterpreterException ex) {
ex.printStackTrace();
}
import org.scilab.modules.graph.ScilabGraph;
import org.scilab.modules.graph.actions.base.VertexSelectionDependantAction;
import org.scilab.modules.gui.menuitem.MenuItem;
-import org.scilab.modules.xcos.block.BasicBlock;
import org.scilab.modules.xcos.graph.XcosDiagram;
import org.scilab.modules.xcos.utils.XcosMessages;
public void actionPerformed(ActionEvent e) {
if (((XcosDiagram) getGraph(null)).getSelectionCell() != null) {
XcosDiagram diagram = (XcosDiagram) getGraph(null);
- ((BasicBlock) diagram.getSelectionCell()).openBlockSettings(diagram
- .getContext());
+
+ // FIXME implement something using the XcosView
+ // ((BasicBlock) diagram.getSelectionCell()).openBlockSettings(diagram
+ // .getContext());
}
}
package org.scilab.modules.xcos.block.actions;
-import static org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.asynchronousScilabExec;
-import static org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.buildCall;
-
import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.util.logging.Logger;
-import org.scilab.modules.action_binding.highlevel.ScilabInterpreterManagement.InterpreterException;
-import org.scilab.modules.graph.ScilabComponent;
import org.scilab.modules.graph.ScilabGraph;
import org.scilab.modules.gui.menuitem.MenuItem;
-import org.scilab.modules.xcos.Xcos;
-import org.scilab.modules.xcos.block.BasicBlock;
-import org.scilab.modules.xcos.block.SuperBlock;
-import org.scilab.modules.xcos.graph.XcosDiagram;
-import org.scilab.modules.xcos.io.scicos.ScicosFormatException;
-import org.scilab.modules.xcos.io.scicos.ScilabDirectHandler;
-import org.scilab.modules.xcos.utils.BlockPositioning;
import org.scilab.modules.xcos.utils.XcosMessages;
/**