| 162 | } |
| 163 | |
| 164 | static Mtl* ComposeMultiMaterial(std::map<std::vector<std::string>, Mtl*>& multi_mats, MtlBaseLib* library, |
| 165 | Interface* max_interface, int& slot, const std::vector<IfcGeom::Material>& materials, |
| 166 | const std::string& object_type, const std::vector<int>& material_ids) |
| 167 | { |
| 168 | std::vector<std::string> material_names; |
| 169 | bool needs_default = std::find(material_ids.begin(), material_ids.end(), -1) != material_ids.end(); |
| 170 | if (needs_default) { |
| 171 | material_names.push_back(object_type); |
| 172 | } |
| 173 | for (auto it = materials.begin(); it != materials.end(); ++it) { |
| 174 | material_names.push_back(it->name()); |
| 175 | } |
| 176 | Mtl* default_material = 0; |
| 177 | if (needs_default) { |
| 178 | default_material = FindMaterialByName(library, object_type); |
| 179 | if (default_material == 0) { |
| 180 | default_material = NewDefaultStdMat(); |
| 181 | default_material->SetName(S(object_type)); |
| 182 | library->Add(default_material); |
| 183 | if (slot < NUM_MATERIAL_SLOTS) { |
| 184 | max_interface->PutMtlToMtlEditor(default_material, slot++); |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | if (material_names.size() == 1) { |
| 189 | if (needs_default) { |
| 190 | return default_material; |
| 191 | } else { |
| 192 | return FindOrCreateMaterial(library, max_interface, slot, *materials.begin()); |
| 193 | } |
| 194 | } |
| 195 | std::map<std::vector<std::string>, Mtl*>::const_iterator i = multi_mats.find(material_names); |
| 196 | if (i != multi_mats.end()) { |
| 197 | return i->second; |
| 198 | } |
| 199 | MultiMtl* multi_mat = NewDefaultMultiMtl(); |
| 200 | multi_mat->SetNumSubMtls((int)material_names.size()); |
| 201 | int mtl_id = 0; |
| 202 | if (needs_default) { |
| 203 | multi_mat->SetSubMtlAndName(mtl_id ++, default_material, default_material->GetName()); |
| 204 | } |
| 205 | for (auto it = materials.begin(); it != materials.end(); ++it) { |
| 206 | Mtl* mtl = FindOrCreateMaterial(library, max_interface, slot, *it); |
| 207 | multi_mat->SetSubMtl(mtl_id ++, mtl); |
| 208 | } |
| 209 | library->Add(multi_mat); |
| 210 | if (slot < NUM_MATERIAL_SLOTS) { |
| 211 | max_interface->PutMtlToMtlEditor(multi_mat,slot++); |
| 212 | } |
| 213 | multi_mats.insert(std::pair<std::vector<std::string>, Mtl*>(material_names, multi_mat)); |
| 214 | return multi_mat; |
| 215 | } |
| 216 | |
| 217 | int IFCImp::DoImport(const TCHAR *name, ImpInterface *impitfc, Interface *itfc, BOOL /*suppressPrompts*/) { |
| 218 |
no test coverage detected