]> gerrit.simantics Code Review - simantics/3d.git/blob
f5118419baf0e7faa314108db268270a670d348f
[simantics/3d.git] /
1 /*******************************************************************************\r
2  * Copyright (c) 2007- VTT Technical Research Centre of Finland.\r
3  * All rights reserved. This program and the accompanying materials\r
4  * are made available under the terms of the Eclipse Public License v1.0\r
5  * which accompanies this distribution, and is available at\r
6  * http://www.eclipse.org/legal/epl-v10.html\r
7  *\r
8  * Contributors:\r
9  *     VTT Technical Research Centre of Finland - initial API and implementation\r
10  *******************************************************************************/\r
11 package org.simantics.processeditor.adapters;\r
12 \r
13 import javax.vecmath.Point3d;\r
14 import javax.vecmath.Vector3d;\r
15 \r
16 import org.simantics.db.Graph;\r
17 import org.simantics.db.Resource;\r
18 import org.simantics.db.adaption.AdaptionException;\r
19 import org.simantics.db.adaption.ResourceAdapter;\r
20 import org.simantics.layer0.utils.EntityFactory;\r
21 import org.simantics.layer0.utils.IEntity;\r
22 import org.simantics.processeditor.ProcessResource;\r
23 import org.simantics.processeditor.actions.PositionType;\r
24 import org.simantics.processeditor.common.ControlPointTools;\r
25 import org.simantics.processeditor.common.PipingTools2.Direction;\r
26 import org.simantics.proconf.g3d.base.Constraint;\r
27 import org.simantics.proconf.g3d.base.G3DTools;\r
28 \r
29 \r
30 public class TurnComponentConstraintAdapter implements ResourceAdapter {\r
31         @SuppressWarnings("unchecked")\r
32         @Override\r
33         public <T> T adapt(Graph graph, Resource resource, Resource mia) throws AdaptionException {\r
34                 Constraint c = new Constraint();\r
35                 assert(graph.isInstanceOf(resource, ProcessResource.plant3Dresource.TurnComponent));\r
36                 IEntity ent = EntityFactory.create(graph,resource);\r
37                 IEntity pcp = ent.getSingleRelatedObject(ProcessResource.plant3Dresource.HasControlPoint);\r
38                 \r
39                 Point3d center = G3DTools.getPoint(pcp.getSingleRelatedObject(ProcessResource.g3dResource.HasWorldPosition));\r
40                 Point3d p1 = ControlPointTools.getRealPosition(pcp, PositionType.NEXT);\r
41                 Point3d p2 = ControlPointTools.getRealPosition(pcp, PositionType.PREVIOUS);\r
42                 Vector3d dir1 = ControlPointTools.getPathLegDirection(pcp, Direction.NEXT);\r
43                 Vector3d dir2 = ControlPointTools.getPathLegDirection(pcp, Direction.PREVIOUS);\r
44                 c.points.add(center);\r
45                 c.points.add(p1);\r
46                 c.points.add(p2);\r
47                 c.dirs.add(dir1);\r
48                 c.dirs.add(dir2);\r
49                 return (T) c;\r
50         }\r
51 \r
52 }\r