Mantis issue 0020750: IMP: Naming during STEP import.

This commit is contained in:
jfa 2010-08-27 11:48:04 +00:00
parent 3a293c4748
commit 343553810e
8 changed files with 184 additions and 55 deletions

View File

@ -65,6 +65,7 @@
#define DESCRIPTION_LABEL 3
#define HISTORY_LABEL 4
#define SUBSHAPES_LABEL 5 // 0020756: GetGroups
#define NAMING_LABEL 6 // 002020750: Naming during STEP import
#define ARGUMENTS _label.FindChild((ARGUMENT_LABEL))
#define ARGUMENT(thePosition) _label.FindChild((ARGUMENT_LABEL)).FindChild((thePosition))
@ -793,6 +794,16 @@ TDF_Label GEOM_Function::GetArgumentHistoryEntry (const TDF_Label& theArgu
return aHistoryCurLabel;
}
//=============================================================================
/*!
* GetNamingEntry
*/
//=============================================================================
TDF_Label GEOM_Function::GetNamingEntry (const Standard_Boolean create)
{
return _label.FindChild(NAMING_LABEL, create);
}
//=======================================================================
//function : GEOM_Function_Type_
//purpose :

View File

@ -269,6 +269,9 @@ public:
Standard_EXPORT TDF_Label GetArgumentHistoryEntry (const TDF_Label& theArgumentRefEntry,
const Standard_Boolean create = Standard_True);
//Returns top label of this function's naming tree
Standard_EXPORT TDF_Label GetNamingEntry (const Standard_Boolean create = Standard_True);
private:
TDF_Label _label;

View File

@ -18,7 +18,6 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include <Standard_Stream.hxx>
@ -109,7 +108,7 @@ Standard_Integer GEOMImpl_ImportDriver::Execute(TFunction_Logbook& log) const
// perform the import
TCollection_AsciiString anError;
TopoDS_Shape aShape = fp( aFileName, aFormatName, anError, aFunction->GetEntry() );
TopoDS_Shape aShape = fp(aFileName, aFormatName, anError, aFunction->GetNamingEntry());
// unload plugin library
// commented by enk:
@ -159,7 +158,8 @@ Standard_EXPORT Handle_Standard_Type& GEOMImpl_ImportDriver_Type_()
//function : DownCast
//purpose :
//=======================================================================
const Handle(GEOMImpl_ImportDriver) Handle(GEOMImpl_ImportDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
const Handle(GEOMImpl_ImportDriver) Handle(GEOMImpl_ImportDriver)::DownCast
(const Handle(Standard_Transient)& AnObject)
{
Handle(GEOMImpl_ImportDriver) _anOtherObject;
@ -169,5 +169,5 @@ const Handle(GEOMImpl_ImportDriver) Handle(GEOMImpl_ImportDriver)::DownCast(cons
}
}
return _anOtherObject ;
return _anOtherObject;
}

View File

@ -265,7 +265,7 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
//if (strlen(theName) == 0) aShapeName += TCollection_AsciiString(aResultSO->Tag());
//else aShapeName = TCollection_AsciiString(CORBA::string_dup(theName));
// try to find existed name for current shape
// BEGIN: try to find existed name for current shape
bool HasName = false;
// recieve current TopoDS shape
CORBA::String_var entry = aShape->GetEntry();
@ -278,24 +278,28 @@ SALOMEDS::SObject_ptr GEOM_Gen_i::PublishInStudy(SALOMEDS::Study_ptr theStudy,
}
entry = aMainSh->GetEntry();
Handle(GEOM_Object) anObj = _impl->GetObject(aMainSh->GetStudyID(), entry);
TDF_Label aMainLbl = anObj->GetEntry();
TDF_Label aMainLbl = anObj->GetFunction(1)->GetNamingEntry();
// check all named shapes using iterator
TDF_ChildIDIterator anIt(aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
for(; anIt.More(); anIt.Next()) {
TDF_ChildIDIterator anIt (aMainLbl, TNaming_NamedShape::GetID(), Standard_True);
for (; anIt.More() && !HasName; anIt.Next()) {
Handle(TNaming_NamedShape) anAttr =
Handle(TNaming_NamedShape)::DownCast(anIt.Value());
if(anAttr.IsNull()) continue;
if (anAttr.IsNull()) continue;
TopoDS_Shape S = anAttr->Get();
if( !S.IsEqual(TopoSh) ) continue;
if (S.IsEqual(TopoSh)) {
TDF_Label L = anAttr->Label();
Handle(TDataStd_Name) aName;
if(L.FindAttribute(TDataStd_Name::GetID(),aName)) {
if (L.FindAttribute(TDataStd_Name::GetID(), aName)) {
aShapeName = aName->Get();
HasName = true;
}
}
}
// END: try to find existed name for current shape
if(!HasName) {
if (!HasName) {
// asv : 11.11.04 Introducing a more sofisticated method of name creation, just as
// it is done in GUI in GEOMBase::GetDefaultName() - not just add a Tag() == number
// of objects in the study, but compute a number of objects with the same prefix

View File

@ -22,7 +22,6 @@
// File: IGESImport.cxx
// Created: Wed May 19 14:36:35 2004
// Author: Pavel TELKOV
// <ptv@mutex.nnov.opencascade.com>
#include "utilities.h"
@ -31,15 +30,26 @@
#include <IFSelect_ReturnStatus.hxx>
#include <IGESControl_Reader.hxx>
#include <IGESData_IGESModel.hxx>
#include <IGESData_IGESEntity.hxx>
#include <Interface_Static.hxx>
#include <Interface_InterfaceModel.hxx>
#include <XSControl_TransferReader.hxx>
#include <XSControl_WorkSession.hxx>
#include <Transfer_TransientProcess.hxx>
#include <Transfer_Binder.hxx>
#include <TransferBRep.hxx>
#include <TNaming_Builder.hxx>
#include <TDF_TagSource.hxx>
#include <TDataStd_Name.hxx>
#include <TDF_Label.hxx>
#include <TCollection_HAsciiString.hxx>
#include <TopoDS_Shape.hxx>
#include <TDF_Label.hxx>
#include <TopoDS_Vertex.hxx>
#include <BRep_Builder.hxx>
#include <gp_Pnt.hxx>
#include <Interface_Static.hxx>
#ifdef WNT
#if defined IGESIMPORT_EXPORTS || defined IGESImport_EXPORTS
@ -71,7 +81,7 @@ IGESIMPORT_EXPORT
TopoDS_Shape Import (const TCollection_AsciiString& theFileName,
const TCollection_AsciiString& theFormatName,
TCollection_AsciiString& theError,
const TDF_Label&)
const TDF_Label& theShapeLabel)
{
// Set "C" numeric locale to save numbers correctly
Kernel_Utils::Localizer loc;
@ -84,19 +94,19 @@ IGESIMPORT_EXPORT
if (status == IFSelect_RetDone) {
if( theFormatName == "IGES_UNIT" ) {
if (theFormatName == "IGES_UNIT") {
Handle(IGESData_IGESModel) aModel =
Handle(IGESData_IGESModel)::DownCast(aReader.Model());
gp_Pnt P(1.0,0.0,0.0);
if(!aModel.IsNull()) {
if (!aModel.IsNull()) {
Handle(TCollection_HAsciiString) aUnitName =
aModel->GlobalSection().UnitName();
//cout<<"aUnitName = "<<aUnitName->ToCString()<<endl;
//cout<<"aUnitFlag = "<<aModel->GlobalSection().UnitFlag()<<endl;
if( aUnitName->String()=="MM" ) {
if (aUnitName->String()=="MM") {
P = gp_Pnt(0.001,0.0,0.0);
}
else if( aUnitName->String()=="CM" ) {
else if (aUnitName->String()=="CM") {
P = gp_Pnt(0.01,0.0,0.0);
}
}
@ -106,12 +116,12 @@ IGESIMPORT_EXPORT
aResShape = V;
return aResShape;
}
if( theFormatName == "IGES_SCALE" ) {
if (theFormatName == "IGES_SCALE") {
//cout<<"need re-scale a model"<<endl;
// set UnitFlag to 'meter'
Handle(IGESData_IGESModel) aModel =
Handle(IGESData_IGESModel)::DownCast(aReader.Model());
if(!aModel.IsNull()) {
if (!aModel.IsNull()) {
IGESData_GlobalSection aGS = aModel->GlobalSection();
aGS.SetUnitFlag(6);
aModel->SetGlobalSection(aGS);
@ -128,6 +138,38 @@ IGESIMPORT_EXPORT
MESSAGE("ImportIGES : count of shapes produced = " << aReader.NbShapes());
aResShape = aReader.OneShape();
// BEGIN: Store names of sub-shapes from file
Handle(Interface_InterfaceModel) Model = aReader.WS()->Model();
Handle(XSControl_TransferReader) TR = aReader.WS()->TransferReader();
if (!TR.IsNull()) {
Handle(Transfer_TransientProcess) TP = /*TransientProcess();*/TR->TransientProcess();
Standard_Integer nb = Model->NbEntities();
for (Standard_Integer i = 1; i <= nb; i++) {
Handle(IGESData_IGESEntity) ent = Handle(IGESData_IGESEntity)::DownCast(Model->Value(i));
if (ent.IsNull() || ! ent->HasName()) continue;
// find target shape
Handle(Transfer_Binder) binder = TP->Find(ent);
if (binder.IsNull()) continue;
TopoDS_Shape S = TransferBRep::ShapeResult(binder);
if (S.IsNull()) continue;
// create label and set shape
TDF_Label L;
TDF_TagSource aTag;
L = aTag.NewChild(theShapeLabel);
TNaming_Builder tnBuild (L);
tnBuild.Generated(S);
// set a name
TCollection_AsciiString string = ent->NameValue()->String();
string.LeftAdjust();
string.RightAdjust();
TCollection_ExtendedString str (string);
TDataStd_Name::Set(L, str);
}
}
// END: Store names
} else {
// switch (status) {
// case IFSelect_RetVoid:

View File

@ -16,13 +16,12 @@
#
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
# File : Makefile.in
# Author : Pavel TELKOV
# Modified by : Alexander BORODIN (OCN) - autotools usage
# Module : GEOM
# $Header$
#
include $(top_srcdir)/adm_local/unix/make_common_starter.am
# Libraries targets
@ -39,5 +38,5 @@ libIGESImport_la_CPPFLAGS = \
libIGESImport_la_LDFLAGS = \
$(STDLIB) \
$(CAS_LDPATH) -lTKIGES \
$(CAS_LDPATH) -lTKIGES -lTKCAF \
$(KERNEL_LDFLAGS) -lSALOMELocalTrace -lSALOMEBasics

View File

@ -43,4 +43,4 @@ libSTEPImport_la_CPPFLAGS = \
libSTEPImport_la_LDFLAGS = \
$(KERNEL_LDFLAGS) -lSALOMELocalTrace -lSALOMEBasics \
$(STDLIB) \
$(CAS_LDPATH) -lTKSTEP
$(CAS_LDPATH) -lTKSTEP -lTKCAF

View File

@ -19,12 +19,10 @@
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// File: STEPImport.cxx
// Created: Wed May 19 14:41:10 2004
// Author: Pavel TELKOV
// <ptv@mutex.nnov.opencascade.com>
//
#include "utilities.h"
#include <Basics_Utils.hxx>
@ -34,13 +32,31 @@
#include <IFSelect_ReturnStatus.hxx>
#include <STEPControl_Reader.hxx>
#include <StepBasic_ProductDefinition.hxx>
#include <StepBasic_ProductDefinitionFormation.hxx>
#include <StepBasic_Product.hxx>
#include <Interface_InterfaceModel.hxx>
#include <XSControl_TransferReader.hxx>
#include <XSControl_WorkSession.hxx>
#include <Transfer_Binder.hxx>
#include <TNaming_Builder.hxx>
#include <TDataStd_Name.hxx>
#include <Transfer_TransientProcess.hxx>
#include <TransferBRep.hxx>
#include <TCollection_AsciiString.hxx>
#include <TopoDS_Compound.hxx>
#include <TopoDS_Shape.hxx>
#include <TDF_Label.hxx>
#include <TDF_Tool.hxx>
#include <Interface_Static.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <TopExp.hxx>
#include <TopoDS_Iterator.hxx>
#include <BRepTools.hxx>
#include <Standard_Failure.hxx>
#include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
@ -70,11 +86,11 @@
extern "C"
{
STEPIMPORT_EXPORT
STEPIMPORT_EXPORT
TopoDS_Shape Import (const TCollection_AsciiString& theFileName,
const TCollection_AsciiString& /*theFormatName*/,
TCollection_AsciiString& theError,
const TDF_Label&)
const TDF_Label& theShapeLabel)
{
MESSAGE("Import STEP model from file " << theFileName.ToCString());
// Set "C" numeric locale to save numbers correctly
@ -87,7 +103,7 @@ STEPIMPORT_EXPORT
//VRV: OCC 4.0 migration
TopoDS_Compound compound;
BRep_Builder B;
B.MakeCompound( compound );
B.MakeCompound(compound);
try {
#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
OCC_CATCH_SIGNALS;
@ -95,13 +111,13 @@ STEPIMPORT_EXPORT
IFSelect_ReturnStatus status = aReader.ReadFile(theFileName.ToCString());
if (status == IFSelect_RetDone) {
Standard_Boolean failsonly = Standard_False ;
aReader.PrintCheckLoad (failsonly, IFSelect_ItemsByEntity);
Standard_Boolean failsonly = Standard_False;
aReader.PrintCheckLoad(failsonly, IFSelect_ItemsByEntity);
/* Root transfers */
Standard_Integer nbr = aReader.NbRootsForTransfer();
aReader.PrintCheckTransfer (failsonly, IFSelect_ItemsByEntity);
aReader.PrintCheckTransfer(failsonly, IFSelect_ItemsByEntity);
for ( Standard_Integer n=1; n <= nbr; n++) {
for (Standard_Integer n = 1; n <= nbr; n++) {
Standard_Boolean ok = aReader.TransferRoot(n);
/* Collecting resulting entities */
Standard_Integer nbs = aReader.NbShapes();
@ -116,22 +132,76 @@ STEPIMPORT_EXPORT
break;
}
for ( Standard_Integer i=1; i<=nbs; i++ ) {
for (Standard_Integer i = 1; i <= nbs; i++) {
TopoDS_Shape aShape = aReader.Shape(i);
if ( aShape.IsNull() ) {
if (aShape.IsNull()) {
// THROW_SALOME_CORBA_EXCEPTION("Null shape in GEOM_Gen_i::ImportStep", SALOME::BAD_PARAM) ;
//return aResShape;
continue;
}
else {
B.Add( compound, aShape ) ;
B.Add(compound, aShape);
}
}
}
if ( aResShape.IsNull() )
if (aResShape.IsNull())
aResShape = compound;
} else {
// BEGIN: Store names of sub-shapes from file
TopTools_IndexedMapOfShape anIndices;
TopExp::MapShapes(aResShape, anIndices);
Handle(Interface_InterfaceModel) Model = aReader.WS()->Model();
Handle(XSControl_TransferReader) TR = aReader.WS()->TransferReader();
if (!TR.IsNull()) {
Handle(Transfer_TransientProcess) TP = TR->TransientProcess();
Handle(Standard_Type) tPD = STANDARD_TYPE(StepBasic_ProductDefinition);
Standard_Integer nb = Model->NbEntities();
for (Standard_Integer ie = 1; ie <= nb; ie++) {
Handle(Standard_Transient) enti = Model->Value(ie);
if (enti->DynamicType() != tPD) continue;
Handle(StepBasic_ProductDefinition) PD =
Handle(StepBasic_ProductDefinition)::DownCast(enti);
if (PD.IsNull()) continue;
Handle(StepBasic_Product) Prod = PD->Formation()->OfProduct();
if (Prod->Name()->UsefullLength() <= 0) continue;
Handle(TCollection_HAsciiString) aName = Prod->Name();
TCollection_ExtendedString aNameExt (aName->ToCString());
// find target shape
Handle(Transfer_Binder) binder = TP->Find(enti);
if (binder.IsNull()) continue;
TopoDS_Shape S = TransferBRep::ShapeResult(binder);
if (S.IsNull()) continue;
// as PRODUCT can be included in the main shape
// several times, we look here for all iclusions.
Standard_Integer isub, nbSubs = anIndices.Extent();
for (isub = 1; isub <= nbSubs; isub++)
{
TopoDS_Shape aSub = anIndices.FindKey(isub);
if (aSub.IsPartner(S)) {
// create label and set shape
TDF_Label L;
TDF_TagSource aTag;
L = aTag.NewChild(theShapeLabel);
TNaming_Builder tnBuild (L);
//tnBuild.Generated(S);
tnBuild.Generated(aSub);
// set a name
TDataStd_Name::Set(L, aNameExt);
}
}
}
}
// END: Store names
}
else {
// switch (status) {
// case IFSelect_RetVoid:
// theError = "Nothing created or No data to process";