1 package com.generalrobotix.ui.item;
4 import java.util.ArrayList;
6 import javax.media.j3d.BadTransformException;
7 import javax.media.j3d.Transform3D;
8 import javax.vecmath.Matrix3d;
9 import javax.vecmath.Matrix4d;
10 import javax.vecmath.Vector3d;
12 import org.eclipse.jface.action.Action;
13 import org.eclipse.jface.action.MenuManager;
14 import org.eclipse.jface.dialogs.InputDialog;
15 import org.eclipse.jface.dialogs.MessageDialog;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.widgets.FileDialog;
32 @SuppressWarnings(
"serial")
38 super(name, manager, model);
39 shapeTransforms_ =
new ArrayList<ShapeTransform>();
40 transformedShapeIndices_ =
new ArrayList<TransformedShapeIndex>();
44 transformedShapeIndices_.add(transformedShapeIndex);
48 ArrayList<Integer> list =
new ArrayList<Integer>();
49 for(
int i=0;
i<transformedShapeIndices_.size();
i++)
51 while(!list.isEmpty()){
52 int inlinedSTMIndex = transformedShapeIndices_.get(list.get(0)).inlinedShapeTransformMatrixIndex;
53 ArrayList<Integer> indices =
new ArrayList<Integer>();
54 indices.add(list.get(0));
55 if(inlinedSTMIndex == -1){
56 setShapeIndex(transformedShapeIndices_.get(list.get(0)));
58 for(
int k=1; k<list.size(); k++){
59 Integer j = list.get(k);
60 if(inlinedSTMIndex == transformedShapeIndices_.get(j).inlinedShapeTransformMatrixIndex){
64 setInlineShapeIndex(inlinedShapeTransformMatrices[inlinedSTMIndex], indices);
66 for(
int k=0; k<indices.size(); k++)
67 list.remove(indices.get(k));
71 private void setShapeIndex(TransformedShapeIndex transformedShapeIndex){
72 Matrix4d mat =
new Matrix4d(transformedShapeIndex.transformMatrix[0], transformedShapeIndex.transformMatrix[1], transformedShapeIndex.transformMatrix[2], transformedShapeIndex.transformMatrix[3],
73 transformedShapeIndex.transformMatrix[4], transformedShapeIndex.transformMatrix[5], transformedShapeIndex.transformMatrix[6], transformedShapeIndex.transformMatrix[7],
74 transformedShapeIndex.transformMatrix[8], transformedShapeIndex.transformMatrix[9], transformedShapeIndex.transformMatrix[10], transformedShapeIndex.transformMatrix[11],
76 ShapeTransform _shapeTransform =
new ShapeTransform(
false, mat,
null, transformedShapeIndex.shapeIndex);
77 shapeTransforms_.add(_shapeTransform);
81 Matrix4d inlinedMat =
new Matrix4d(inlinedMatrix[0], inlinedMatrix[1], inlinedMatrix[2], inlinedMatrix[3],
82 inlinedMatrix[4], inlinedMatrix[5], inlinedMatrix[6], inlinedMatrix[7],
83 inlinedMatrix[8], inlinedMatrix[9], inlinedMatrix[10], inlinedMatrix[11],
85 Matrix4d[] mat =
new Matrix4d[indices.size()];
86 int[] indices0 =
new int[indices.size()];
87 for(
int i=0;
i<indices.size();
i++){
88 TransformedShapeIndex transformedShapeIndex = transformedShapeIndices_.get(indices.get(
i));
89 mat[
i] =
new Matrix4d(transformedShapeIndex.transformMatrix[0], transformedShapeIndex.transformMatrix[1], transformedShapeIndex.transformMatrix[2], transformedShapeIndex.transformMatrix[3],
90 transformedShapeIndex.transformMatrix[4], transformedShapeIndex.transformMatrix[5], transformedShapeIndex.transformMatrix[6], transformedShapeIndex.transformMatrix[7],
91 transformedShapeIndex.transformMatrix[8], transformedShapeIndex.transformMatrix[9], transformedShapeIndex.transformMatrix[10], transformedShapeIndex.transformMatrix[11],
93 indices0[
i] = transformedShapeIndex.shapeIndex;
95 ShapeTransform _shapeTransform =
new ShapeTransform(
true, mat, inlinedMat, indices0);
96 shapeTransforms_.add(_shapeTransform);
101 for(
int i=0;
i<shapeTransforms_.size();
i++){
103 if(!shapeTransforms_.get(
i).isInline_)
104 shapeItem.
loadShape(shapeTransforms_.get(
i).transform_[0], shapeTransforms_.get(
i).shapeIndices_[0], segmentT);
106 shapeItem.
loadInlineShape(shapeTransforms_.get(
i).transform_, shapeTransforms_.get(
i).inlinedTransform_, shapeTransforms_.get(
i).shapeIndices_, segmentT);
117 if( fPath !=
null ) {
119 ModelLoader mloader = ModelLoaderHelper.narrow(
121 mloader._non_existent();
122 SceneInfo sInfo = mloader.loadSceneInfo(fPath);
123 int n=children_.size();
131 }
catch(ModelLoaderException me){
135 fPath +
"\n\n" + me.description);
136 System.out.println(
"Failed to load scene info:" + fPath);
137 me.printStackTrace();
138 }
catch(Exception ex){
142 System.out.println(
"Failed to load scene info:" + fPath);
143 ex.printStackTrace();
150 int n=children_.size();
152 if(name.equals(
"Box"))
153 type = ShapePrimitiveType._SP_BOX;
154 else if(name.equals(
"Cone"))
155 type = ShapePrimitiveType._SP_CONE;
156 else if(name.equals(
"Cylinder"))
157 type = ShapePrimitiveType._SP_CYLINDER;
158 else if(name.equals(
"Sphere"))
159 type = ShapePrimitiveType._SP_SPHERE;
170 Matrix3d m =
new Matrix3d(w[0],w[1],w[2],w[4],w[5],w[6],w[8],w[9],w[10]);
171 double[] p = {w[3], w[7], w[11]};
175 double [] rot =
new double[4];
181 Transform3D t3d =
new Transform3D();
182 tg_.getTransform(t3d);
183 Matrix4d
ret =
new Matrix4d();
189 Transform3D t3d =
new Transform3D();
190 tg_.getTransform(t3d);
191 Vector3d v =
new Vector3d();
193 double[]
ret =
new double[3];
200 Transform3D t3d =
new Transform3D();
201 tg_.getTransform(t3d);
202 Matrix3d mat =
new Matrix3d();
206 double[]
ret =
new double[4];
217 double [] pos = getDblAry(value);
218 if (translation(pos)){
231 if (pos ==
null || pos.length != 3)
return false;
232 Vector3d v =
new Vector3d(pos);
233 Transform3D t3d =
new Transform3D();
234 tg_.getTransform(t3d);
235 t3d.setTranslation(v);
236 setDblAry(
"translation", pos, 4);
237 if (model_ !=
null && parent_ !=
null) model_.notifyModified();
239 tg_.setTransform(t3d);
240 }
catch(BadTransformException e){
241 System.out.println(
"Invalid translation:"+v+
" is applied to "+getName());
253 double [] rot = getDblAry(value);
267 if (rot ==
null || rot.length != 4)
return false;
268 Transform3D t3d =
new Transform3D();
269 tg_.getTransform(t3d);
271 tg_.setTransform(t3d);
272 setDblAry(
"rotation", rot, 4);
273 if (model_ !=
null && parent_ !=
null) model_.notifyModified();
287 InputDialog dialog =
new InputDialog(
null,
getText(),
289 if ( dialog.open() == InputDialog.OK && dialog.getValue() !=
null)
290 rename( dialog.getValue() );
302 MessageBundle.
get(
"GrxSensorItem.dialog.message.delete") + getName() +
" ?") )
315 fdlg.setFilterExtensions(
new String[]{
"*.wrl"});
316 fdlg.setFilterPath(getDefaultDir().getAbsolutePath());
317 String fPath = fdlg.open();
318 System.out.println(
"fPath = "+fPath);
319 if( fPath !=
null ) {
321 setDefaultDirectory(
new File(fPath).getParent());
328 MenuManager subMenu=
new MenuManager(
MessageBundle.
get(
"GrxLinkItem.menu.primitiveShape"));
335 addPrimitiveShape(
"Box");
344 addPrimitiveShape(
"Cone");
353 addPrimitiveShape(
"Cylinder");
362 addPrimitiveShape(
"Sphere");
371 if (model_ !=
null) model_.notifyModified();
375 class ShapeTransform {
376 public boolean isInline_ =
false;
377 public Matrix4d[] transform_ =
null;
378 public Matrix4d inlinedTransform_ =
null;
379 public int[] shapeIndices_ =
null;
381 public ShapeTransform(
boolean isInline, Matrix4d mat, Matrix4d inlinedMat,
int index){
382 isInline_ = isInline;
383 transform_ =
new Matrix4d[1];
385 inlinedTransform_ = inlinedMat;
386 shapeIndices_ =
new int[1];
387 shapeIndices_[0] = index;
390 public ShapeTransform(
boolean isInline, Matrix4d[] mat, Matrix4d inlinedMat,
int[] indices){
391 isInline_ = isInline;
393 inlinedTransform_ = inlinedMat;
394 shapeIndices_ = indices;
static final String get(String key)
png_infop png_charp png_int_32 png_int_32 int * type
#define null
our own NULL pointer
png_infop png_charpp name
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
item corresponds to a robot model
void loadnewInlineShape(SceneInfo sInfo)
static final int ADD_ITEM
void setURL(String url)
set URL property
static Shell getCurrentShell()
void setMatrix(Matrix3d m1)
void loadInlineShape(Matrix4d[] shapeT, Matrix4d inlinedT, int[] index, Matrix4d segmentT)
static org.omg.CORBA.Object getReference(String id)
get CORBA object which is associated with id
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
def getText(self, nodes=None)
void loadShape(Matrix4d shapeT, int index, Matrix4d segmentT)
void createnewPrimitiveShape(int type)