Loading files
3d097a032This file is pinned to the selected release. Download the original to open it in your design tool.
// Created on: 2004-11-24
// Created by: Edward AGAPOV
// Copyright (c) 2004-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
// The original implementation Copyright: (C) RINA S.p.A
#include "XmlTObjDrivers_ReferenceDriver.hxx"
#include <TDF_Tool.hxx>
#include <TDF_Attribute.hxx>
#include <XmlObjMgt.hxx>
#include <XmlObjMgt_Persistent.hxx>
#include <XmlObjMgt_RRelocationTable.hxx>
#include <TObj_TReference.hxx>
#include <TObj_Model.hxx>
#include <TObj_Object.hxx>
#include <TObj_Assistant.hxx>
IMPLEMENT_STANDARD_RTTIEXT(XmlTObjDrivers_ReferenceDriver, XmlMDF_ADriver)
IMPLEMENT_DOMSTRING(MasterEntry, "master")
IMPLEMENT_DOMSTRING(ReferredEntry, "entry")
IMPLEMENT_DOMSTRING(ReferredModelEntry, "modelentry")
//=================================================================================================
XmlTObjDrivers_ReferenceDriver::XmlTObjDrivers_ReferenceDriver(
const occ::handle<Message_Messenger>& theMessageDriver)
: XmlMDF_ADriver(theMessageDriver, nullptr)
{
}
//=================================================================================================
occ::handle<TDF_Attribute> XmlTObjDrivers_ReferenceDriver::NewEmpty() const
{
return new TObj_TReference;
}
//=================================================================================================
bool XmlTObjDrivers_ReferenceDriver::Paste(const XmlObjMgt_Persistent& Source,
const occ::handle<TDF_Attribute>& Target,
XmlObjMgt_RRelocationTable& /*RelocTable*/) const
{
const XmlObjMgt_Element& anElement = Source;
// get entries
TCollection_AsciiString RefEntry = anElement.getAttribute(::ReferredEntry());
TCollection_AsciiString MasterEntry = anElement.getAttribute(::MasterEntry());
// entry in model holder
TCollection_AsciiString InHolderEntry = anElement.getAttribute(::ReferredModelEntry());
// master label
TDF_Label aLabel, aMasterLabel;
TDF_Tool::Label(Target->Label().Data(), MasterEntry, aMasterLabel);
// referred label
if (InHolderEntry.IsEmpty())
{
TDF_Tool::Label(Target->Label().Data(), RefEntry, aLabel, true);
}
else
{
occ::handle<TObj_Model> aModel = TObj_Assistant::FindModel(InHolderEntry.ToCString());
TDF_Tool::Label(aModel->GetLabel().Data(), RefEntry, aLabel, true);
}
occ::handle<TObj_TReference> aTarget = occ::down_cast<TObj_TReference>(Target);
aTarget->Set(aLabel, aMasterLabel);
return !aLabel.IsNull() && !aMasterLabel.IsNull();
}
//=================================================================================================
void XmlTObjDrivers_ReferenceDriver::Paste(const occ::handle<TDF_Attribute>& Source,
XmlObjMgt_Persistent& Target,
XmlObjMgt_SRelocationTable& /*RelocTable*/) const
{
occ::handle<TObj_TReference> aSource = occ::down_cast<TObj_TReference>(Source);
occ::handle<TObj_Object> aLObject = aSource->Get();
if (aLObject.IsNull())
{
return;
}
// referred entry
TCollection_AsciiString entry;
TDF_Label aLabel = aLObject->GetLabel();
TDF_Tool::Entry(aLabel, entry);
Target.Element().setAttribute(::ReferredEntry(), entry.ToCString());
// master entry
entry.Clear();
TDF_Label aMasterLabel = aSource->GetMasterLabel();
TDF_Tool::Entry(aMasterLabel, entry);
Target.Element().setAttribute(::MasterEntry(), entry.ToCString());
// is reference to other document
if (aLabel.Root() == aMasterLabel.Root())
{
return;
}
occ::handle<TObj_Model> aModel = aLObject->GetModel();
TCollection_AsciiString aModelName(aModel->GetModelName()->String());
Target.Element().setAttribute(::ReferredModelEntry(), aModelName.ToCString());
}