1 package fi.vtt.simantics.processeditor.adapters;
\r
3 import javax.vecmath.Point3d;
\r
4 import javax.vecmath.Vector3d;
\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
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
20 public class TurnComponentConstraintAdapter implements ResourceAdapter {
\r
21 @SuppressWarnings("unchecked")
\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
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