From 69b0ca19c69c7804533cbd27af2b80f4a0b95c51 Mon Sep 17 00:00:00 2001 From: Johnny Sit Date: Fri, 10 Apr 2020 18:24:54 -0400 Subject: [PATCH 1/2] creation of view so far --- .../service/TransformationService.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/main/java/com/lmco/spectrum/systemnavigation3d/service/TransformationService.java b/src/main/java/com/lmco/spectrum/systemnavigation3d/service/TransformationService.java index e9cecbf..d49f157 100644 --- a/src/main/java/com/lmco/spectrum/systemnavigation3d/service/TransformationService.java +++ b/src/main/java/com/lmco/spectrum/systemnavigation3d/service/TransformationService.java @@ -3,6 +3,8 @@ package com.lmco.spectrum.systemnavigation3d.service; import com.lmco.spectrum.systemnavigation3d.domain.catia.DocumentSMG; import org.springframework.stereotype.Service; import org.w3c.dom.Element; +import org.w3c.dom.Attr; +import org.w3c.dom.Document; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; @@ -13,6 +15,8 @@ import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; +import java.text.SimpleDateFormat; + @Service public class TransformationService { @@ -27,6 +31,10 @@ public class TransformationService { private static final String ATTR_NAME = "Name"; private static final String ATTR_VALUE = "Value"; + // view tags + private static final String TAG_VIEW = "CLitView"; + private static final String ATTR_IDENT = "Ident"; + // TODO make functional // TODO consider types of transformations we need to make // accept list of transformation options? @@ -40,9 +48,72 @@ public class TransformationService { } ensureViewMode(doc); setFocusedView(doc, "32-11-01 Pivot"); + createView(doc,"testView"); return marshal(doc); } + private void createView(DocumentSMG doc, String viewName) { + + for(Element el : doc.getNodes()){ + Element currentChild = (Element) el.getFirstChild(); + + if(el.getTagName().equals(TAG_SERVER) + && el.hasAttribute(ATTR_TYPE) + && el.getAttribute(ATTR_TYPE).equals(SERVER_TYPE_CLitList) + && !currentChild.getTagName().equals("CLitVersionHistory") + ) { + Document smgDoc = el.getOwnerDocument(); + Element newView = smgDoc.createElement(TAG_VIEW); + el.appendChild(newView); + + Attr ident = smgDoc.createAttribute(ATTR_IDENT); + ident.setValue(new SimpleDateFormat("HH.mm.ss").format(new java.util.Date())); + newView.setAttributeNode(ident); + + Attr name = smgDoc.createAttribute(ATTR_NAME); + name.setValue(viewName); + newView.setAttributeNode(name); + + Attr type = smgDoc.createAttribute(ATTR_TYPE); + type.setValue("1"); + newView.setAttributeNode(type); + + break; + + /* + Attr ATD = smgDoc.createAttribute("AppliedToDigger"); + ATD.setValue("1"); + newView.setAttributeNode(ATD); + + Attr ATO = smgDoc.createAttribute("AppliedToObject"); + ATO.setValue("1"); + newView.setAttributeNode(ATO); + + Attr ATV = smgDoc.createAttribute("AppliedToVisibility"); + ATO.setValue("1"); + newView.setAttributeNode(ATV); + + Attr ATS = smgDoc.createAttribute("AppliedToSelection"); + ATS.setValue("0"); + newView.setAttributeNode(ATS); + + Attr AZFA = smgDoc.createAttribute("AppliedZoomFitAll"); + ATS.setValue("0"); + newView.setAttributeNode(AZFA); + + Attr ALP = smgDoc.createAttribute("AppliedLocationProps"); + ALP.setValue("0"); + newView.setAttributeNode(ALP); + + Attr ATMP = smgDoc.createAttribute("AppliedToMaterialProps"); + ATMP.setValue("0"); + newView.setAttributeNode(ATMP); + + */ + } + } + } + private void ensureViewMode(DocumentSMG doc) { for(Element el : doc.getNodes()) { if(el.getTagName().equals(TAG_SERVER) From c3cef35b72a8715a5777daa796c168fcf72ebcfd Mon Sep 17 00:00:00 2001 From: Johnny Sit Date: Sat, 11 Apr 2020 15:29:38 -0400 Subject: [PATCH 2/2] creation of a view --- .../service/TransformationService.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main/java/com/lmco/spectrum/systemnavigation3d/service/TransformationService.java b/src/main/java/com/lmco/spectrum/systemnavigation3d/service/TransformationService.java index db4796f..80fbaf2 100644 --- a/src/main/java/com/lmco/spectrum/systemnavigation3d/service/TransformationService.java +++ b/src/main/java/com/lmco/spectrum/systemnavigation3d/service/TransformationService.java @@ -4,6 +4,7 @@ import com.lmco.spectrum.systemnavigation3d.domain.catia.DocumentSMG; import com.lmco.spectrum.systemnavigation3d.dto.TransformerOptions; import org.springframework.stereotype.Service; import org.w3c.dom.Element; +import org.w3c.dom.Document; import javax.annotation.Nullable; import javax.xml.bind.JAXBContext; @@ -15,6 +16,8 @@ import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; +import java.text.SimpleDateFormat; + @Service public class TransformationService { @@ -29,6 +32,10 @@ public class TransformationService { private static final String ATTR_NAME = "Name"; private static final String ATTR_VALUE = "Value"; + // view tags + private static final String TAG_VIEW = "CLitView"; + private static final String ATTR_IDENT = "Ident"; + // TODO make functional // TODO consider types of transformations we need to make // accept list of transformation options? @@ -51,10 +58,33 @@ public class TransformationService { if(options.getSetFocusedView() != null) { ensureViewMode(doc); setFocusedView(doc, options.getSetFocusedView()); + createView(doc, "test"); } return doc; } + private void createView(DocumentSMG doc, String viewName) { + + for(Element el : doc.getNodes()){ + if(el.getTagName().equals(TAG_SERVER) + && el.hasAttribute(ATTR_TYPE) + && el.getAttribute(ATTR_TYPE).equals(SERVER_TYPE_CLitList) + ) { + Document smgDoc = el.getOwnerDocument(); + Element newView = smgDoc.createElement(TAG_VIEW); + el.appendChild(newView); + + newView.setAttribute(ATTR_IDENT, new SimpleDateFormat("HH.mm.ss").format(new java.util.Date())); + + newView.setAttribute(ATTR_NAME, viewName); + + newView.setAttribute(ATTR_TYPE, "1"); + + break; + } + } + } + private void ensureViewMode(DocumentSMG doc) { for(Element el : doc.getNodes()) { if(el.getTagName().equals(TAG_SERVER)