Skip to content

Commit

Permalink
Xcos: first version using the MVC
Browse files Browse the repository at this point in the history
No more no less than before : just instantiate a diagram.

Change-Id: Ib435a5b7027e73c88cebd3761546f47746c275b4
  • Loading branch information
davidcl authored and Antoine ELIAS committed Sep 10, 2015
1 parent 5348f2e commit 6a88f6b
Show file tree
Hide file tree
Showing 137 changed files with 2,986 additions and 11,258 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,3 +1,3 @@
/workspace/
/workspace*/
.DS_Store
/.gitreview
5 changes: 3 additions & 2 deletions scilab/.gitignore
Expand Up @@ -108,6 +108,7 @@ ipch
_UpgradeReport_Files/
UpgradeLog.XML


# eclipse temp files
workspace/
.checkstyle
Expand All @@ -116,8 +117,8 @@ workspace/
.cproject
.settings/

# VIM ctags temp files
tags
# vim files
/tags

# MacOS files
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion scilab/modules/scicos/includes/Controller.hxx
Expand Up @@ -69,7 +69,7 @@ public:
};

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)
Expand Down
2 changes: 2 additions & 0 deletions scilab/modules/scicos/includes/Model.hxx
Expand Up @@ -47,6 +47,7 @@ public:
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;

Expand All @@ -57,6 +58,7 @@ public:
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);

Expand Down
Expand Up @@ -13,9 +13,17 @@
#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
Expand All @@ -24,7 +32,7 @@ namespace view_scilab
/*
* Shared data between adapters
*/
class Adapters
class SCICOS_IMPEXP Adapters
{
public:
typedef enum
Expand All @@ -46,6 +54,8 @@ public:
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:

Expand Down
101 changes: 83 additions & 18 deletions scilab/modules/scicos/sci_gateway/cpp/sci_scicos_new.cpp
Expand Up @@ -12,6 +12,7 @@

#include <string>

#include "../../includes/view_scilab/Adapters.hxx"
#include "gw_scicos.hxx"

#include "types.hxx"
Expand All @@ -21,7 +22,6 @@
#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"
Expand Down Expand Up @@ -129,25 +129,9 @@ types::InternalType * alloc_and_set_as_mlist(types::String* type_name, types::ty
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)
Expand Down Expand Up @@ -258,3 +242,84 @@ types::Function::ReturnValue sci_scicos_new(types::typed_list &in, int _iRetCoun

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;
}
}

Expand Up @@ -12,14 +12,14 @@

#include <string>

#include "../../includes/view_scilab/Adapters.hxx"
#include "gw_scicos.hxx"

#include "types.hxx"
#include "string.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"
Expand Down
2 changes: 1 addition & 1 deletion scilab/modules/scicos/src/c/scicos.vcxproj
Expand Up @@ -326,6 +326,7 @@ lib /DEF:"$(ProjectDir)differential_equations_f_Import.def" /SUBSYSTEM:WINDOWS /
<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" />
Expand All @@ -341,7 +342,6 @@ lib /DEF:"$(ProjectDir)differential_equations_f_Import.def" /SUBSYSTEM:WINDOWS /
<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" />
Expand Down
6 changes: 3 additions & 3 deletions scilab/modules/scicos/src/c/scicos.vcxproj.filters
Expand Up @@ -337,9 +337,6 @@
<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>
Expand Down Expand Up @@ -379,6 +376,9 @@
<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>
Expand Down
51 changes: 51 additions & 0 deletions scilab/modules/scicos/src/cpp/Model_getObjectProperties.cpp
Expand Up @@ -549,6 +549,57 @@ bool Model::getObjectProperty(ScicosID uid, kind_t k, object_properties_t p, std
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);
Expand Down
51 changes: 51 additions & 0 deletions scilab/modules/scicos/src/cpp/Model_setObjectProperties.cpp
Expand Up @@ -501,6 +501,57 @@ update_status_t Model::setObjectProperty(ScicosID uid, kind_t k, object_properti
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);
Expand Down

0 comments on commit 6a88f6b

Please sign in to comment.