]> gerrit.simantics Code Review - simantics/3d.git/blob
e21bda74e747b102a1b5d459a593db58e43b2121
[simantics/3d.git] /
1 package fi.vtt.simantics.processeditor.adapters;\r
2 \r
3 import javax.vecmath.Point3d;\r
4 import javax.vecmath.Vector3d;\r
5 \r
6 import org.simantics.db.Graph;\r
7 import org.simantics.db.Resource;\r
8 import org.simantics.db.adaption.AdaptionException;\r
9 import org.simantics.db.adaption.ResourceAdapter;\r
10 import org.simantics.layer0.utils.EntityFactory;\r
11 import org.simantics.layer0.utils.IEntity;\r
12 import org.simantics.proconf.g3d.base.Constraint;\r
13 \r
14 import fi.vtt.simantics.processeditor.ProcessResource;\r
15 import fi.vtt.simantics.processeditor.common.PipingTools2;\r
16 \r
17 public class InlineComponentConstraintAdapter implements ResourceAdapter {\r
18         @SuppressWarnings("unchecked")\r
19         @Override\r
20         public <T> T adapt(Graph graph, Resource resource, Resource mia) throws AdaptionException {\r
21                 Constraint c = new Constraint();\r
22                 assert(graph.isInstanceOf(resource, ProcessResource.plant3Dresource.InlineComponent));\r
23                 IEntity ent = EntityFactory.create(graph,resource);\r
24                 Point3d center = new Point3d();\r
25                 Point3d p1 = new Point3d();\r
26                 Point3d p2 = new Point3d();\r
27                 Vector3d dir = new Vector3d();\r
28                 PipingTools2.getInlineComponentEnds(ent, center, p1, p2, dir);\r
29                 c.points.add(center);\r
30                 c.points.add(p1);\r
31                 c.points.add(p2);\r
32                 c.dirs.add(dir);\r
33                 return (T) c;\r
34         }\r
35 \r
36 }\r