]> gerrit.simantics Code Review - simantics/3d.git/blob
e52dbe7342c0cbe6b3e11f313834681e1ea22e8a
[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.common.PipingTools2;\r
24 import org.simantics.proconf.g3d.base.Constraint;\r
25 \r
26 \r
27 public class InlineComponentConstraintAdapter implements ResourceAdapter {\r
28         @SuppressWarnings("unchecked")\r
29         @Override\r
30         public <T> T adapt(Graph graph, Resource resource, Resource mia) throws AdaptionException {\r
31                 Constraint c = new Constraint();\r
32                 assert(graph.isInstanceOf(resource, ProcessResource.plant3Dresource.InlineComponent));\r
33                 IEntity ent = EntityFactory.create(graph,resource);\r
34                 Point3d center = new Point3d();\r
35                 Point3d p1 = new Point3d();\r
36                 Point3d p2 = new Point3d();\r
37                 Vector3d dir = new Vector3d();\r
38                 PipingTools2.getInlineComponentEnds(ent, center, p1, p2, dir);\r
39                 c.points.add(center);\r
40                 c.points.add(p1);\r
41                 c.points.add(p2);\r
42                 c.dirs.add(dir);\r
43                 return (T) c;\r
44         }\r
45 \r
46 }\r