Statistics
| Branch: | Revision:

root / src / org.omnetpp.ide.nativelibs / layout.i @ 0418c1a0

History | View | Annotate | Download (5.55 KB)

1
%module LayoutEngine
2

    
3
// covariant return type warning disabled
4
#pragma SWIG nowarn=822
5

    
6
%include "loadlib.i"
7
%include "enumtypeunsafe.swg"
8
%include "commondefs.i"
9
%javaconst(1);
10

    
11
%{
12
#include "graphlayouter.h"
13
#include "basicspringembedderlayout.h"
14
#include "forcedirectedgraphlayouter.h"
15
#include "geometry.h"
16
#include "forcedirectedparametersbase.h"
17
#include "forcedirectedparameters.h"
18
#include "forcedirectedembedding.h"
19
%}
20

    
21
// hide export/import macros from swig
22
#define COMMON_API
23
#define LAYOUT_API
24
#define OPP_DLLEXPORT
25
#define OPP_DLLIMPORT
26

    
27
#define NAMESPACE_BEGIN
28
#define NAMESPACE_END
29
#define USING_NAMESPACE
30

    
31
%typemap(jni)    cModule* "jobject"
32
%typemap(jtype)  cModule* "Object"
33
%typemap(jstype) cModule* "Object"
34
%typemap(javain) cModule* "$javainput"
35

    
36
%include "std_common.i"
37
%include "std_string.i"
38
%include "std_vector.i"
39

    
40
%typemap(javacode) Variable %{
41
    protected Variable disown() {
42
        swigCMemOwn = false;
43
        return this;
44
    }
45

    
46
    public boolean equals(Object obj) {
47
        return (obj instanceof Variable) && getCPtr(this)==getCPtr((Variable)obj);
48
    }
49
    public int hashCode() {
50
        return (int)getCPtr(this);
51
    }
52
%}
53

    
54
%typemap(javain) Variable * "Variable.getCPtr($javainput.disown())";
55

    
56
%typemap(javain) IBody * "IBody.getCPtr($javainput.disown())";
57

    
58
%typemap(javaimports) IBody %{
59
import java.lang.reflect.Constructor;
60
%}
61

    
62
%typemap(javaout) IBody * {
63
   return IBody.newIBody($jnicall, $owner);
64
}
65

    
66
%typemap(javacode) IBody %{
67
   protected IBody disown() {
68
      swigCMemOwn = false;
69
      return this;
70
   }
71

    
72
   @SuppressWarnings("unchecked")
73
   private static java.util.ArrayList<Constructor> bodyConstructors = new java.util.ArrayList<Constructor>();
74

    
75
   @SuppressWarnings("unchecked")
76
   public static IBody newIBody(long cPtr, boolean isOwner) {
77
      try {
78
         if (cPtr == 0)
79
            return null;
80

    
81
         String className = LayoutEngineJNI.IBody_getClassName(cPtr, null);
82
         Constructor constructor = null;
83
         for (int i = 0; i < bodyConstructors.size(); i++)
84
            if (bodyConstructors.get(i).getName().equals(className))
85
               constructor = bodyConstructors.get(i);
86

    
87
         if (constructor == null)
88
         {
89
            String name = "org.omnetpp.common.engine." + className;
90
            Class clazz = Class.forName(name);
91
            constructor = clazz.getDeclaredConstructor(long.class, boolean.class);
92
            bodyConstructors.add(constructor);
93
         }
94

    
95
         return (IBody)constructor.newInstance(cPtr, isOwner);
96
      }
97
      catch (Exception e) {
98
         throw new RuntimeException(e);
99
      }
100
   }
101
%}
102

    
103
%typemap(javain) IForceProvider * "IForceProvider.getCPtr($javainput.disown())";
104

    
105
%typemap(javaimports) IForceProvider %{
106
import java.lang.reflect.Constructor;
107
%}
108

    
109
%typemap(javaout) IForceProvider * {
110
   return IForceProvider.newIForceProvider($jnicall, $owner);
111
}
112

    
113
%typemap(javacode) IForceProvider %{
114
   protected IForceProvider disown() {
115
      swigCMemOwn = false;
116
      return this;
117
   }
118

    
119
   @SuppressWarnings("unchecked")
120
   private static java.util.ArrayList<Constructor> forceProviderConstructors = new java.util.ArrayList<Constructor>();
121

    
122
   @SuppressWarnings("unchecked")
123
   public static IForceProvider newIForceProvider(long cPtr, boolean isOwner) {
124
      try {
125
         if (cPtr == 0)
126
            return null;
127

    
128
         // we implement polymorphic return types:
129
         String className = LayoutEngineJNI.IForceProvider_getClassName(cPtr, null);
130
         Constructor constructor = null;
131
         for (int i = 0; i < forceProviderConstructors.size(); i++)
132
            if (forceProviderConstructors.get(i).getName().equals(className))
133
               constructor = forceProviderConstructors.get(i);
134

    
135
         if (constructor == null)
136
         {
137
            String name = "org.omnetpp.common.engine." + className;
138
            Class clazz = Class.forName(name);
139
            constructor = clazz.getDeclaredConstructor(long.class, boolean.class);
140
            forceProviderConstructors.add(constructor);
141
         }
142

    
143
         return (IForceProvider)constructor.newInstance(cPtr, isOwner);
144
      }
145
      catch (Exception e) {
146
         throw new RuntimeException(e);
147
      }
148
   }
149
%}
150

    
151
namespace std {
152
   %template(CcList) vector<Cc>;
153
   %template(IBodyList) vector<IBody *>;
154
   %template(IForceProviderList) vector<IForceProvider *>;
155
   %template(PtList) vector<Pt>;
156
   %template(VariableList) vector<Variable *>;
157
};
158

    
159
%define FIXUP_GETNODEPOSITION(CLASS)
160
%ignore CLASS::getNodePosition;
161
%extend CLASS {
162
   int getNodePositionX(cModule *mod) {int x,y; self->getNodePosition(mod, x, y); return x;}
163
   int getNodePositionY(cModule *mod) {int x,y; self->getNodePosition(mod, x, y); return y;}
164
}
165
%enddef
166

    
167
FIXUP_GETNODEPOSITION(GraphLayouter);
168
FIXUP_GETNODEPOSITION(BasicSpringEmbedderLayout);
169
FIXUP_GETNODEPOSITION(ForceDirectedGraphLayouter);
170

    
171
/*
172
XXX to ignore:
173
  getDistanceAndVector()
174
  getStandardVerticalDistanceAndVector()
175
  getSlipperyDistanceAndVector()
176
*/
177

    
178
%ignore zero;
179
%ignore NaN;
180
%ignore POSITIVE_INFINITY;
181
%ignore isNaN;
182
%ignore ForceDirectedEmbedding::parameters;
183
%ignore ForceDirectedEmbedding::writeDebugInformation;
184
%ignore LeastExpandedSpring::LeastExpandedSpring;   //XXX takes std::vector<AbstractSpring*>
185

    
186
%include "graphlayouter.h"
187
%include "basicspringembedderlayout.h"
188
%include "forcedirectedgraphlayouter.h"
189
%include "geometry.h"
190
%include "forcedirectedparametersbase.h"
191
%include "forcedirectedparameters.h"
192
%include "forcedirectedembedding.h"
193