001/* 002 * (C) Copyright 2006-2016 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Tiago Cardoso <tcardoso@nuxeo.com> 018 */ 019package org.nuxeo.ecm.platform.threed; 020 021import org.nuxeo.ecm.core.api.Blob; 022 023import java.io.Serializable; 024import java.util.HashMap; 025import java.util.List; 026import java.util.Map; 027 028/** 029 * Object wrapping a transmission format with {@link ThreeD} and LoD details 030 * 031 * @since 8.4 032 */ 033public class TransmissionThreeD extends ThreeD { 034 035 public static final String NAME = "name"; 036 037 public static final String CONTENT = "content"; 038 039 public static final String PERC_POLY = "percPoly"; 040 041 public static final String MAX_POLY = "maxPoly"; 042 043 public static final String PERC_TEX = "percTex"; 044 045 public static final String MAX_TEX = "maxTex"; 046 047 public static final String INFO = "info"; 048 049 protected final Integer percPoly; 050 051 protected final Long maxPoly; 052 053 protected final Integer percTex; 054 055 protected final String maxTex; 056 057 protected final String name; 058 059 public TransmissionThreeD(Blob blob, List<Blob> resources, ThreeDInfo info, Integer percPoly, Long maxPoly, 060 Integer percTex, String maxTex, String name) { 061 super(blob, resources, info); 062 this.percPoly = percPoly; 063 this.maxPoly = maxPoly; 064 this.percTex = percTex; 065 this.maxTex = maxTex; 066 this.name = name; 067 } 068 069 public TransmissionThreeD(Map<String, Serializable> map) { 070 super((Blob) map.get(CONTENT), null, 071 (map.get(INFO) != null) ? new ThreeDInfo((Map<String, Serializable>) map.get(INFO)) : null); 072 name = (String) map.get(NAME); 073 Long percPolyLong = (Long) map.get(PERC_POLY); 074 percPoly = (percPolyLong != null) ? percPolyLong.intValue() : null; 075 Long maxPolyLong = (Long) map.get(MAX_POLY); 076 maxPoly = (maxPolyLong != null) ? maxPolyLong : null; 077 Long percTexLong = (Long) map.get(PERC_POLY); 078 percTex = (percTexLong != null) ? percTexLong.intValue() : null; 079 maxTex = (String) map.get(MAX_TEX); 080 } 081 082 public String getTitle() { 083 return name; 084 } 085 086 public Integer getPercPoly() { 087 return percPoly; 088 } 089 090 public Long getMaxPoly() { 091 return maxPoly; 092 } 093 094 public Integer getPercTex() { 095 return percTex; 096 } 097 098 public String getMaxTex() { 099 return maxTex; 100 } 101 102 public String getName() { 103 return name; 104 } 105 106 public String getId() { 107 return String.valueOf(name.hashCode() & 0x7fffffff); 108 } 109 110 public Map<String, Serializable> toMap() { 111 Map<String, Serializable> map = new HashMap<>(); 112 map.put(NAME, name); 113 map.put(CONTENT, (Serializable) blob); 114 map.put(PERC_POLY, percPoly); 115 map.put(MAX_POLY, maxPoly); 116 map.put(PERC_TEX, percTex); 117 map.put(MAX_TEX, maxTex); 118 map.put(INFO, (info != null) ? (Serializable) info.toMap() : null); 119 return map; 120 } 121}