]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling/src/org/simantics/modeling/typicals/rules/TransformRule.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.modeling / src / org / simantics / modeling / typicals / rules / TransformRule.java
1 /*******************************************************************************
2  * Copyright (c) 2012 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.modeling.typicals.rules;
13
14 import java.awt.geom.AffineTransform;
15
16 import org.simantics.db.Resource;
17 import org.simantics.db.WriteGraph;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.diagram.synchronization.graph.DiagramGraphUtil;
20 import org.simantics.modeling.typicals.ITypicalSynchronizationRule;
21 import org.simantics.modeling.typicals.TypicalInfo;
22
23 /**
24  * @author Tuukka Lehtonen
25  */
26 public enum TransformRule implements ITypicalSynchronizationRule {
27
28     INSTANCE;
29
30     public static TransformRule getInstance() {
31         return INSTANCE;
32     }
33
34     @Override
35     public boolean synchronize(WriteGraph graph, Resource template, Resource instance, TypicalInfo info) throws DatabaseException {
36         AffineTransform at = DiagramGraphUtil.getAffineTransform(graph, template);
37         AffineTransform copyAt = DiagramGraphUtil.getAffineTransform(graph, instance);
38         if (!at.equals(copyAt)) {
39             info.messageLog.add("\t\t\ttransform");
40             DiagramGraphUtil.setTransform(graph, instance, at);
41             return true;
42         }
43         return false;
44     }
45
46 }