]> gerrit.simantics Code Review - simantics/3d.git/blob
4df00b555758146ff90f138f8d8cbfc0ea516738
[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 import org.simantics.proconf.g3d.base.G3DTools;\r
14 \r
15 import fi.vtt.simantics.processeditor.ProcessResource;\r
16 import fi.vtt.simantics.processeditor.actions.PositionType;\r
17 import fi.vtt.simantics.processeditor.common.ControlPointTools;\r
18 import fi.vtt.simantics.processeditor.common.PipingTools2.Direction;\r
19 \r
20 public class TurnComponentConstraintAdapter implements ResourceAdapter {\r
21         @SuppressWarnings("unchecked")\r
22         @Override\r
23         public <T> T adapt(Graph graph, Resource resource, Resource mia) throws AdaptionException {\r
24                 Constraint c = new Constraint();\r
25                 assert(graph.isInstanceOf(resource, ProcessResource.plant3Dresource.TurnComponent));\r
26                 IEntity ent = EntityFactory.create(graph,resource);\r
27                 IEntity pcp = ent.getSingleRelatedObject(ProcessResource.plant3Dresource.HasControlPoint);\r
28                 \r
29                 Point3d center = G3DTools.getPoint(pcp.getSingleRelatedObject(ProcessResource.g3dResource.HasWorldPosition));\r
30                 Point3d p1 = ControlPointTools.getRealPosition(pcp, PositionType.NEXT);\r
31                 Point3d p2 = ControlPointTools.getRealPosition(pcp, PositionType.PREVIOUS);\r
32                 Vector3d dir1 = ControlPointTools.getPathLegDirection(pcp, Direction.NEXT);\r
33                 Vector3d dir2 = ControlPointTools.getPathLegDirection(pcp, Direction.PREVIOUS);\r
34                 c.points.add(center);\r
35                 c.points.add(p1);\r
36                 c.points.add(p2);\r
37                 c.dirs.add(dir1);\r
38                 c.dirs.add(dir2);\r
39                 return (T) c;\r
40         }\r
41 \r
42 }\r