]> OCCT Git - occt-copy.git/commitdiff
0031388: Data Exchange - support kinematics data in STEP format
authordpasukhi <dpasukhi@opencascade.com>
Thu, 30 Jul 2020 21:59:13 +0000 (00:59 +0300)
committerdpasukhi <dpasukhi@opencascade.com>
Fri, 31 Jul 2020 09:32:36 +0000 (12:32 +0300)
# add support for multiple reference shapes for kinematic link
# fix lost reference joint of kinematic value
# fix unsupported adding geom params for linear pair
# fix useless check conditions in the XDRAW_Kinematics

20 files changed:
src/STEPCAFControl/STEPCAFControl_Reader.cxx
src/STEPCAFControl/STEPCAFControl_Writer.cxx
src/StepToGeom/StepToGeom.cxx
src/XCAFDoc/XCAFDoc.cxx
src/XCAFDoc/XCAFDoc_KinematicPair.cxx
src/XCAFDoc/XCAFDoc_KinematicPairValue.cxx
src/XCAFDoc/XCAFDoc_KinematicPairValue.hxx
src/XCAFDoc/XCAFDoc_KinematicTool.cxx
src/XCAFDoc/XCAFDoc_KinematicTool.hxx
src/XCAFKinematics/XCAFKinematics_HighOrderPairObject.hxx
src/XCAFKinematics/XCAFKinematics_LowOrderPairObject.hxx
src/XCAFKinematics/XCAFKinematics_PairValueObject.cxx
src/XDEDRAW/XDEDRAW.cxx
src/XDEDRAW/XDEDRAW_Kinematics.cxx
tests/gdt/kinematics/A1
tests/gdt/kinematics_export/A1 [deleted file]
tests/gdt/kinematics_export/A2 [deleted file]
tests/gdt/kinematics_export/bug31388_1 [new file with mode: 0644]
tests/gdt/kinematics_export/bug31388_2 [new file with mode: 0644]
tests/gdt/kinematics_export/end

index 3567d4cde2bee479696e075c59d8a5471386b19b..fa7192968a1c97e3834c42141ca3529eff6d7311 100644 (file)
@@ -4318,13 +4318,13 @@ void collectViewShapes(const Handle(XSControl_WorkSession)& theWS,
 //purpose  : set links of the Kinematic Joint in the OCAF
 //=======================================================================
 Standard_Boolean addLinkWithShapes(const Handle(XSControl_WorkSession)& theWS,
-                                    const Handle(TDocStd_Document)& theDoc,
-                                    const Handle(StepKinematics_KinematicLinkRepresentation)& theLinkRepresentation,
-                                    const TDF_Label& theMechanism,
-                                    const XCAFDoc_DataMapOfShapeLabel& theMap,
-                                    TDF_Label& theLink,
-                                    NCollection_DataMap<Handle(StepKinematics_KinematicLinkRepresentation), TDF_Label>& theMapOfLinks,
-                                    const Standard_Boolean& theIsBase = Standard_False)
+                                   const Handle(TDocStd_Document)& theDoc,
+                                   const Handle(StepKinematics_KinematicLinkRepresentation)& theLinkRepresentation,
+                                   const TDF_Label& theMechanism,
+                                   const XCAFDoc_DataMapOfShapeLabel& theMap,
+                                   TDF_Label& theLink,
+                                   NCollection_DataMap<Handle(StepKinematics_KinematicLinkRepresentation), TDF_Label>& theMapOfLinks,
+                                   const Standard_Boolean& theIsBase = Standard_False)
 {
   Handle(XSControl_TransferReader) aTR = theWS->TransferReader();
   Handle(Transfer_TransientProcess) aTP = aTR->TransientProcess();
@@ -4337,33 +4337,34 @@ Standard_Boolean addLinkWithShapes(const Handle(XSControl_WorkSession)& theWS,
     return Standard_True;
   Handle(StepKinematics_KinematicLinkRepresentationAssociation) aKLRA1;
   for (Interface_EntityIterator anIterLinks = aGraph.Sharings(theLinkRepresentation);
-    anIterLinks.More() && aKLRA1.IsNull(); anIterLinks.Next())
-  {
+    anIterLinks.More(); anIterLinks.Next()) {
     aKLRA1 = Handle(StepKinematics_KinematicLinkRepresentationAssociation)::DownCast(anIterLinks.Value());
+    if (aKLRA1.IsNull())
+      continue;
+
+    Handle(StepKinematics_ContextDependentKinematicLinkRepresentation) aCDKLR;
+    Interface_EntityIterator entIt = aGraph.Sharings(aKLRA1);
+    for (entIt.Start(); entIt.More() & aCDKLR.IsNull(); entIt.Next())
+    {
+      aCDKLR = Handle(StepKinematics_ContextDependentKinematicLinkRepresentation)::DownCast(entIt.Value());
+    }
+    if (aCDKLR.IsNull())
+      continue;
+    Handle(StepRepr_PropertyDefinition) aPD =
+      Handle(StepRepr_PropertyDefinition)::DownCast(aCDKLR->RepresentedProductRelation());
+    if (aPD.IsNull())
+      continue;
+    TDF_Label aShapeLabel;
+    Handle(Transfer_Binder) binder = aTP->Find(aPD->Definition().Value());
+    TopoDS_Shape aShape = TransferBRep::ShapeResult(aTP, binder);
+    if (aShape.IsNull())
+      continue;
+    if (theMap.IsBound(aShape))
+      aShapes.Append(theMap(aShape));
+    else if (aSTool->Search(aShape, aShapeLabel))
+      aShapes.Append(aShapeLabel);
   }
-  if (aKLRA1.IsNull())
-    return Standard_False;
-  Handle(StepKinematics_ContextDependentKinematicLinkRepresentation) aCDKLR;
-  Interface_EntityIterator entIt = aGraph.Sharings(aKLRA1);
-  for (entIt.Start(); entIt.More() & aCDKLR.IsNull(); entIt.Next())
-  {
-    aCDKLR = Handle(StepKinematics_ContextDependentKinematicLinkRepresentation)::DownCast(entIt.Value());
-  }
-  Handle(StepRepr_PropertyDefinition) aPD =
-    Handle(StepRepr_PropertyDefinition)::DownCast(aCDKLR->RepresentedProductRelation());
-  if (aPD.IsNull())
-    return Standard_False;
-  TDF_Label aShapeLabel;
-  Handle(Transfer_Binder) binder = aTP->Find(aPD->Definition().Value());
-  TopoDS_Shape aShape = TransferBRep::ShapeResult(aTP, binder);
-  if (aShape.IsNull())
-    return Standard_False;
-  if (theMap.IsBound(aShape))
-    aShapeLabel = theMap(aShape);
-  else
-    aSTool->Search(aShape, aShapeLabel, Standard_True, Standard_True, Standard_True);
-  aShapes.Append(aShapeLabel);
-  if (aShapes.Length() == 0)
+  if (aShapes.IsEmpty())
     return Standard_False;
 
   theLink = aKTool->AddLink(theMechanism, aShapes, theIsBase); 
@@ -4719,7 +4720,7 @@ Handle(XCAFKinematics_PairObject) createXCAFKinematicPairObject(const Handle(Ste
 }
 
 //=======================================================================
-//function : setPairValue
+//function : setKinematicPairValue
 //purpose  : set pair Value of the kinematic pair in OCAF
 //=======================================================================
 Standard_Boolean setKinematicPairValue(const Handle(XSControl_WorkSession)& theWS,
index 6aa1ee7d8e483f7efc9359ffa28ba3938c0a2e63..87b6f372be51e590519a92e7b10ae03cd6fe5fb2 100644 (file)
@@ -2194,44 +2194,33 @@ Standard_Boolean STEPCAFControl_Writer::WriteSHUOs (const Handle(XSControl_WorkS
 //function : createKinematicLink
 //purpose  : auxilary
 //=======================================================================
-static Standard_Boolean createKinematicLink(const Handle(Transfer_FinderProcess)& FP,
+static Standard_Boolean createKinematicLink(const Handle(XSControl_WorkSession)& theWS,
                                             const Handle(XCAFDoc_KinematicTool)& theKTool,
                                             const Interface_Graph& theGraph,
-                                            const TDF_Label& theLabelLink,  
-                                            Handle(StepKinematics_KinematicLinkRepresentation)& theLinkRepresentation,
-                                            Handle(StepKinematics_KinematicLink)& theLink,
-                                            Handle(StepShape_ShapeRepresentation)& theShapeRepr,
-                                            Handle(StepRepr_PropertyDefinition)& thePDS)
+                                            const TDF_Label& theLabelLink,
+                                            NCollection_IndexedDataMap<TDF_Label, Handle(StepKinematics_KinematicLinkRepresentation), TDF_LabelMapHasher>& theMapOfLinks,
+                                            Handle(StepKinematics_RigidLinkRepresentation)& theBaseLink,
+                                            Handle(StepRepr_PropertyDefinition)& theGeneralPD)
 {
-  theLink = new StepKinematics_KinematicLink;
+  const Handle(Interface_InterfaceModel)& Model = theWS->Model();
+  const Handle(XSControl_TransferWriter)& TW = theWS->TransferWriter();
+  const Handle(Transfer_FinderProcess)& FP = TW->FinderProcess();
+  Handle(StepKinematics_KinematicLink) aLink = new StepKinematics_KinematicLink;
 
   Handle(TDataStd_Name) aNameLink;
   Handle(TCollection_HAsciiString) aHNameLink;
   if (theLabelLink.FindAttribute(TDataStd_Name::GetID(), aNameLink))
     aHNameLink = new TCollection_HAsciiString(aNameLink->Get());
-  else
-    aHNameLink = new TCollection_HAsciiString("Link "+ theLabelLink.Tag());
-  theLink->Init(aHNameLink);
-
-  // find ref shapes
-  TDF_LabelSequence aShapesStartL = theKTool->GetRefShapes(theLabelLink);
-  if (aShapesStartL.IsEmpty()) return Standard_False;
-  TopoDS_Shape aTopoShapeStart = XCAFDoc_ShapeTool::GetShape(aShapesStartL.Value(1));
-  TopLoc_Location aLocStart;
-  TColStd_SequenceOfTransient seqRI;
-  FindEntities(FP, aTopoShapeStart, aLocStart, seqRI);
-  if (seqRI.Length() <= 0) {
-    FP->Messenger()->SendInfo() << "Warning: Cannot find RI for " << aTopoShapeStart.TShape()->DynamicType()->Name() << std::endl;
-    return Standard_False;
-  }
+  aLink->Init(aHNameLink);
 
   //Choose type of the representation link
+  Handle(StepKinematics_KinematicLinkRepresentation) aLinkRepr;
   TDF_LabelSequence aJoints = theKTool->GetJointsOfLink(theLabelLink,Standard_True,Standard_False);
   Standard_Boolean isLinear = Standard_False;
-  for (Standard_Integer anIndOfJoint = 1; anIndOfJoint <= aJoints.Length(); ++anIndOfJoint)
+  for (TDF_LabelSequence::Iterator anItJoint(aJoints); anItJoint.More(); anItJoint.Next())
   {
     Handle(XCAFDoc_KinematicPair) aKPairAttr;
-    if (!aJoints(anIndOfJoint).FindAttribute(XCAFDoc_KinematicPair::GetID(), aKPairAttr))
+    if (!anItJoint.Value().FindAttribute(XCAFDoc_KinematicPair::GetID(), aKPairAttr))
       continue;
     Handle(XCAFKinematics_PairObject) aPairObject = aKPairAttr->GetObject();
     if (aPairObject->Type() == XCAFKinematics_PairType_LinearFlexibleAndPinion ||
@@ -2241,28 +2230,74 @@ static Standard_Boolean createKinematicLink(const Handle(Transfer_FinderProcess)
       return Standard_False;
   }
   if (isLinear)
-    theLinkRepresentation = new StepKinematics_LinearFlexibleLinkRepresentation;
+    aLinkRepr = new StepKinematics_LinearFlexibleLinkRepresentation;
   else
-    theLinkRepresentation = new StepKinematics_RigidLinkRepresentation;
+    aLinkRepr = new StepKinematics_RigidLinkRepresentation;
 
-  // get PDS of Shape
-  Interface_EntityIterator anIter = theGraph.Sharings(seqRI.Value(1));
-  for (anIter.Start(); anIter.More() && thePDS.IsNull(); anIter.Next()) {
-    theShapeRepr = Handle(StepShape_ShapeRepresentation)::DownCast(anIter.Value());
-    if (theShapeRepr.IsNull())
+  Model->AddEntity(aLink);
+  Model->AddEntity(aLinkRepr);
+
+  // find ref shapes
+  TDF_LabelSequence aShapesL = theKTool->GetRefShapes(theLabelLink);
+  if (aShapesL.IsEmpty())
+    return Standard_False;
+  for (TDF_LabelSequence::Iterator anItShapes(aShapesL); anItShapes.More(); anItShapes.Next()) {
+    TopoDS_Shape aTopoShape = XCAFDoc_ShapeTool::GetShape(anItShapes.Value());
+    TopLoc_Location aLoc;
+    TColStd_SequenceOfTransient seqRI;
+    FindEntities(FP, aTopoShape, aLoc, seqRI);
+    if (seqRI.Length() <= 0) {
+      FP->Messenger()->SendInfo() << "Warning: Cannot find RI for " << aTopoShape.TShape()->DynamicType()->Name() << std::endl;
       continue;
-    Interface_EntityIterator aSDRIt = theGraph.Sharings(theShapeRepr);
-    for (aSDRIt.Start(); aSDRIt.More() && thePDS.IsNull(); aSDRIt.Next()) {
-      Handle(StepShape_ShapeDefinitionRepresentation) aSDR =
-        Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aSDRIt.Value());
-      if (aSDR.IsNull()) continue;
-      thePDS = aSDR->Definition().PropertyDefinition();
-      if (!thePDS.IsNull())
-        return Standard_True;
     }
+
+    // get PDS of Shape
+    Handle(StepShape_ShapeRepresentation) aShapeRepr;
+    Handle(StepRepr_PropertyDefinition) aPD;
+    Interface_EntityIterator anItRI = theGraph.Sharings(seqRI.Value(1));
+    for (anItRI.Start(); anItRI.More() && aPD.IsNull(); anItRI.Next()) {
+      aShapeRepr = Handle(StepShape_ShapeRepresentation)::DownCast(anItRI.Value());
+      if (aShapeRepr.IsNull())
+        continue;
+      Interface_EntityIterator aSDRIt = theGraph.Sharings(aShapeRepr);
+      for (aSDRIt.Start(); aSDRIt.More() && aPD.IsNull(); aSDRIt.Next()) {
+        Handle(StepShape_ShapeDefinitionRepresentation) aSDR =
+          Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aSDRIt.Value());
+        if (aSDR.IsNull()) continue;
+        aPD = aSDR->Definition().PropertyDefinition();
+      }
+    }
+    if (aPD.IsNull())
+      return Standard_False;
+    Handle(StepRepr_RepresentationContext) aRepresentationContextOfLink = aShapeRepr->ContextOfItems();
+
+    Handle(TCollection_HAsciiString) aNameOfLinkRepr = new TCollection_HAsciiString("");
+    Handle(StepRepr_HArray1OfRepresentationItem) aPlacementsOfPairs = new StepRepr_HArray1OfRepresentationItem();
+    aLinkRepr->Init(aNameOfLinkRepr, aPlacementsOfPairs, aRepresentationContextOfLink, aLink);
+    theMapOfLinks.Add(theLabelLink, aLinkRepr);
+
+    if (theGeneralPD.IsNull() && !isLinear)
+      theGeneralPD = aPD;
+
+    Handle(TDataStd_Integer) aBase;
+    if (theBaseLink.IsNull() && theLabelLink.FindAttribute(TDataStd_Integer::GetID(), aBase)) {
+      theGeneralPD = aPD;
+      theBaseLink = Handle(StepKinematics_RigidLinkRepresentation)::DownCast(aLinkRepr);
+    }
+
+    Handle(StepKinematics_KinematicLinkRepresentationAssociation) aLinkRepresentationAssociation = new StepKinematics_KinematicLinkRepresentationAssociation;
+    aLinkRepresentationAssociation->Init(aNameOfLinkRepr, aNameOfLinkRepr, aLinkRepr, aShapeRepr);
+    Handle(StepKinematics_ContextDependentKinematicLinkRepresentation) aCDKLRS = new StepKinematics_ContextDependentKinematicLinkRepresentation;
+    Handle(StepKinematics_ProductDefinitionRelationshipKinematics) aPDRK = new StepKinematics_ProductDefinitionRelationshipKinematics;
+    theGeneralPD = aPD;
+    aPDRK->Init(aNameOfLinkRepr, Standard_False, aLinkRepresentationAssociation->Description(), aPD->Definition());
+    aCDKLRS->Init(aLinkRepresentationAssociation, aPDRK);
+    Model->AddEntity(aLinkRepresentationAssociation);
+    Model->AddEntity(aPDRK);
+    Model->AddEntity(aCDKLRS);
   }
 
-  return Standard_False;
+  return Standard_True;
 }
 
 //=======================================================================
@@ -2514,11 +2549,6 @@ static Standard_Boolean createKinematicPair(const Handle(XCAFKinematics_PairObje
     }
     case(XCAFKinematics_PairType_Planar):
     {
-      if (isRanged)
-        theKinematicPair = new StepKinematics_PlanarPairWithRange;
-      else
-        theKinematicPair = new StepKinematics_PlanarPair;
-
       aTZ = Standard_False;
       aRX = Standard_False;
       aRY = Standard_False;
@@ -2695,7 +2725,7 @@ static Standard_Boolean createKinematicPair(const Handle(XCAFKinematics_PairObje
     }
     return Standard_True;
   }
-  else if (theKinPairObj->IsKind(STANDARD_TYPE(XCAFKinematics_HighOrderPairObject))) //need to fix
+  else if (theKinPairObj->IsKind(STANDARD_TYPE(XCAFKinematics_HighOrderPairObject)))
   {
   Handle(XCAFKinematics_HighOrderPairObject) aHighOrderPairObject = Handle(XCAFKinematics_HighOrderPairObject)::DownCast(theKinPairObj);
     switch (theKinPairObj->Type())
@@ -2854,6 +2884,10 @@ static Standard_Boolean createKinematicPair(const Handle(XCAFKinematics_PairObje
   return Standard_False;
 }
 
+//=======================================================================
+//function : createKinematicPairValue
+//purpose  : 
+//=======================================================================
 static Standard_Boolean createKinematicPairValue(const Handle(XCAFKinematics_PairValueObject)& theKinPairValueObj,
                                                  const Handle(StepKinematics_PairRepresentationRelationship)& thePairReprRelationship,
                                                  Handle(StepKinematics_PairValue)& thePairValue)
@@ -2889,14 +2923,6 @@ static Standard_Boolean createKinematicPairValue(const Handle(XCAFKinematics_Pai
     break;
   }
   case(XCAFKinematics_PairType_Universal):
-  {
-    thePairValue = new StepKinematics_UniversalPairValue;
-    Handle(StepKinematics_UniversalPairValue) aUniversalPairValue =
-      Handle(StepKinematics_UniversalPairValue)::DownCast(thePairValue);
-    aUniversalPairValue->SetFirstRotationAngle(theKinPairValueObj->GetFirstRotation());
-    aUniversalPairValue->SetSecondRotationAngle(theKinPairValueObj->GetSecondRotation());
-    break;
-  }
   case(XCAFKinematics_PairType_Homokinetic):
   {
     thePairValue = new StepKinematics_UniversalPairValue;
@@ -2907,15 +2933,6 @@ static Standard_Boolean createKinematicPairValue(const Handle(XCAFKinematics_Pai
     break;
   }
   case(XCAFKinematics_PairType_Spherical):
-  {
-    thePairValue = new StepKinematics_SphericalPairValue;
-    Handle(StepKinematics_SphericalPairValue) aSphericalPairValue =
-      Handle(StepKinematics_SphericalPairValue)::DownCast(thePairValue);
-    StepKinematics_SpatialRotation InputRotation;
-    InputRotation.SetValue(theKinPairValueObj->GetAllValues());
-    aSphericalPairValue->SetInputOrientation(InputRotation);
-    break;
-  }
   case(XCAFKinematics_PairType_SphericalWithPin):
   {
     thePairValue = new StepKinematics_SphericalPairValue;
@@ -3122,55 +3139,29 @@ Standard_EXPORT Standard_Boolean STEPCAFControl_Writer::WriteKinematics(const Ha
     return Standard_False;
 
   TDF_LabelSequence aMechanismsL;
-
-  aMechanismsL.Clear();
   aMechanismsL = aKTool->GetMechanisms();
   if (aMechanismsL.Length() <= 0) return Standard_False;
 
-  Standard_Integer aMechInd;
-  for (Standard_Integer aMechInd = 1; aMechInd <= aMechanismsL.Length(); aMechInd++)
+  for (TDF_LabelSequence::Iterator anItMech(aMechanismsL); anItMech.More(); anItMech.Next())
   {
     // write Links
     Handle(StepKinematics_RigidLinkRepresentation) aBaseLinkOfMech;
     Handle(StepRepr_PropertyDefinition) aGeneralDefinition;
 
-    TDF_LabelSequence aSeqOfLinskL = aKTool->GetLinks(aMechanismsL.Value(aMechInd));
+    TDF_LabelSequence aSeqOfLinskL = aKTool->GetLinks(anItMech.Value());
     if (aSeqOfLinskL.Length() <= 0)
       continue;
     NCollection_IndexedDataMap<TDF_Label, Handle(StepKinematics_KinematicLinkRepresentation), TDF_LabelMapHasher> aMapOfLinks;
 
-    for (Standard_Integer aLinkInd = 1; aLinkInd <= aSeqOfLinskL.Length(); aLinkInd++)
+    for (TDF_LabelSequence::Iterator anItLink(aSeqOfLinskL); anItLink.More(); anItLink.Next())
     {
-      TDF_Label aLinkL = aSeqOfLinskL.Value(aLinkInd);
+      TDF_Label aLinkL = anItLink.Value();
       Handle(StepKinematics_KinematicLink) aLink;
       Handle(StepShape_ShapeRepresentation) aRefShapeOfLink;
       Handle(StepRepr_PropertyDefinition) aPD;    
       Handle(StepKinematics_KinematicLinkRepresentation) aLinkRepresentation;
-      if (!createKinematicLink(FP, aKTool, aGraph, aLinkL, aLinkRepresentation, aLink, aRefShapeOfLink, aPD))
+      if (!createKinematicLink(theWS, aKTool, aGraph, aLinkL, aMapOfLinks, aBaseLinkOfMech, aGeneralDefinition))
         continue;
-      Handle(StepRepr_RepresentationContext) aRepresentationContextOfLink = aRefShapeOfLink->ContextOfItems();
-
-      Handle(TCollection_HAsciiString) aNameOfLinkRepr = new TCollection_HAsciiString("");
-      Handle(StepRepr_HArray1OfRepresentationItem) aPlacementsOfPairs = new StepRepr_HArray1OfRepresentationItem;
-      aLinkRepresentation->Init(aNameOfLinkRepr, aPlacementsOfPairs, aRepresentationContextOfLink, aLink);
-      aMapOfLinks.Add(aSeqOfLinskL(aLinkInd), aLinkRepresentation);
-
-      Handle(TDataStd_Integer) aBase;
-      if (aBaseLinkOfMech.IsNull() && aLinkL.FindAttribute(TDataStd_Integer::GetID(), aBase))
-        aBaseLinkOfMech = Handle(StepKinematics_RigidLinkRepresentation)::DownCast(aLinkRepresentation);
-
-      Handle(StepKinematics_KinematicLinkRepresentationAssociation) aLinkRepresentationAssociation = new StepKinematics_KinematicLinkRepresentationAssociation;
-      aLinkRepresentationAssociation->Init(aNameOfLinkRepr, aNameOfLinkRepr, aLinkRepresentation, aRefShapeOfLink);
-      Handle(StepKinematics_ContextDependentKinematicLinkRepresentation) aCDKLRS = new StepKinematics_ContextDependentKinematicLinkRepresentation;
-      Handle(StepKinematics_ProductDefinitionRelationshipKinematics) aPDRK = new StepKinematics_ProductDefinitionRelationshipKinematics;
-      aGeneralDefinition = aPD;
-      aPDRK->Init(aNameOfLinkRepr, Standard_False, aLinkRepresentationAssociation->Description(), aPD->Definition());
-      aCDKLRS->Init(aLinkRepresentationAssociation, aPDRK);
-      Model->AddEntity(aLink);
-      Model->AddEntity(aLinkRepresentation);
-      Model->AddEntity(aLinkRepresentationAssociation);
-      Model->AddEntity(aPDRK);
-      Model->AddEntity(aCDKLRS);
     }
     if (aGeneralDefinition.IsNull())
       continue;
@@ -3183,7 +3174,7 @@ Standard_EXPORT Standard_Boolean STEPCAFControl_Writer::WriteKinematics(const Ha
       continue;
 
     // write joints
-    TDF_LabelSequence aSeqOfJointsL = aKTool->GetJoints(aMechanismsL.Value(aMechInd));
+    TDF_LabelSequence aSeqOfJointsL = aKTool->GetJoints(anItMech.Value());
     if (aSeqOfJointsL.Length() <= 0) 
       continue;
     NCollection_IndexedDataMap<TDF_Label, Handle(StepKinematics_KinematicJoint), TDF_LabelMapHasher> aMapofJoints;
@@ -3193,9 +3184,10 @@ Standard_EXPORT Standard_Boolean STEPCAFControl_Writer::WriteKinematics(const Ha
     Handle(StepKinematics_MechanismRepresentation) aMechanism = new StepKinematics_MechanismRepresentation;
     StepRepr_RepresentedDefinition aPDK;
     Handle(StepKinematics_KinematicTopologyStructure) aKTopoStruct = new StepKinematics_KinematicTopologyStructure;
-    for (Standard_Integer aJointInd = 1; aJointInd <= aSeqOfJointsL.Length(); aJointInd++)
+    Standard_Integer aJointInd = 1;
+    for (TDF_LabelSequence::Iterator anItJoint(aSeqOfJointsL); anItJoint.More(); anItJoint.Next())
     {
-      TDF_Label aJointL = aSeqOfJointsL.Value(aJointInd);
+      TDF_Label aJointL = anItJoint.Value();
       Handle(StepKinematics_KinematicJoint) aJoint;
       Handle(XCAFDoc_KinematicPair) aKPairAttr;
       Handle(StepKinematics_KinematicPair) aKinematicPair;
@@ -3208,7 +3200,7 @@ Standard_EXPORT Standard_Boolean STEPCAFControl_Writer::WriteKinematics(const Ha
         continue;
       if (!createKinematicPair(aPairObject,aJoint,aKinematicPair, aLinkRepr1, aLinkRepr2))
         continue;
-      aMapofJoints.Add(aSeqOfJointsL(aJointInd), aJoint);
+      aMapofJoints.Add(anItJoint.Value(), aJoint);
       Handle(StepKinematics_PairRepresentationRelationship) aPairReprRelationship = new StepKinematics_PairRepresentationRelationship;
       StepRepr_RepresentationOrRepresentationReference aDataLinkStart;
       aDataLinkStart.SetValue(aLinkRepr1);
@@ -3218,7 +3210,7 @@ Standard_EXPORT Standard_Boolean STEPCAFControl_Writer::WriteKinematics(const Ha
       aPair.SetValue(aKinematicPair);
       Handle(TCollection_HAsciiString) aDescription;
       aPairReprRelationship->Init(aKinematicPair->Name(), aKinematicPair->Name(), Standard_False, aDescription, aDataLinkStart, aDataLinkEnd, aPair);
-      anArrayOfPairs->SetValue(aJointInd, aPairReprRelationship);
+      anArrayOfPairs->SetValue(aJointInd++, aPairReprRelationship);
 
       Model->AddEntity(aJoint);
       Model->AddWithRefs(aPairReprRelationship);
@@ -3231,7 +3223,7 @@ Standard_EXPORT Standard_Boolean STEPCAFControl_Writer::WriteKinematics(const Ha
     StepKinematics_KinematicTopologyRepresentationSelect aTopoSelect;
     aTopoSelect.SetValue(aKTopoStruct);
     Handle(TDataStd_Name) aAttrName;
-    aMechanismsL.Value(aMechInd).FindAttribute(TDataStd_Name::GetID(), aAttrName);
+    anItMech.Value().FindAttribute(TDataStd_Name::GetID(), aAttrName);
     Handle(TCollection_HAsciiString) aHNameMechanism = new TCollection_HAsciiString(aAttrName->Get());
     aPDK.SetValue(aProductDefKin);
     aMechanism->Init(aHNameMechanism, anArrayOfPairs, aBaseLinkOfMech->ContextOfItems(), aTopoSelect);
@@ -3239,17 +3231,18 @@ Standard_EXPORT Standard_Boolean STEPCAFControl_Writer::WriteKinematics(const Ha
     Model->AddWithRefs(aPropertyMechanismRepr);
 
     // (optional) write States
-    TDF_LabelSequence aSeqOfStates = aKTool->GetStates(aMechanismsL.Value(aMechInd));
-    for (Standard_Integer aStateInd = 1; aStateInd <= aSeqOfStates.Length(); ++aStateInd)
+    TDF_LabelSequence aSeqOfStates = aKTool->GetStates(anItMech.Value());
+    for (TDF_LabelSequence::Iterator anItState(aSeqOfStates); anItState.More(); anItState.Next())
     {
       Handle(StepKinematics_MechanismStateRepresentation) aStateRepr = new StepKinematics_MechanismStateRepresentation;
-      TDF_LabelSequence aSeqOfValues = aKTool->GetValuesOfState(aSeqOfStates(aStateInd));
+      TDF_LabelSequence aSeqOfValues = aKTool->GetValuesOfState(anItState.Value());
       if (aSeqOfValues.IsEmpty())
         continue;
       Handle(StepRepr_HArray1OfRepresentationItem) aItems = new StepRepr_HArray1OfRepresentationItem(1, aSeqOfValues.Length());
-      for (Standard_Integer aValueInd = 1; aValueInd <= aItems->Length(); ++aValueInd)
+      Standard_Integer aValueInd = 1;
+      for (TDF_LabelSequence::Iterator anItValue(aSeqOfValues); anItValue.More(); anItValue.Next())
       {
-        TDF_Label aJointL = aKTool->GetJointOfValue(aSeqOfValues(aValueInd));
+        TDF_Label aJointL = aKTool->GetJointOfValue(anItValue.Value());
         Handle(StepKinematics_KinematicJoint) aJoint;
         Handle(StepKinematics_PairRepresentationRelationship) aPairReprRelationship;
         if (!aMapofJoints.FindFromKey(aJointL, aJoint))
@@ -3258,22 +3251,22 @@ Standard_EXPORT Standard_Boolean STEPCAFControl_Writer::WriteKinematics(const Ha
         if (aPairReprRelationship.IsNull())
           continue;
         Handle(XCAFDoc_KinematicPairValue) aKPairValueAttr;
-        if (!aSeqOfValues(aValueInd).FindAttribute(XCAFDoc_KinematicPairValue::GetID(), aKPairValueAttr))
+        if (!anItValue.Value().FindAttribute(XCAFDoc_KinematicPairValue::GetID(), aKPairValueAttr))
           continue;
         Handle(TCollection_HAsciiString) aNameOfValue;
         Handle(TDataStd_Name) aNameAttr;
-        if (aSeqOfValues(aValueInd).FindAttribute(TDataStd_Name::GetID(), aNameAttr))
+        if (anItValue.Value().FindAttribute(TDataStd_Name::GetID(), aNameAttr))
           aNameOfValue = new TCollection_HAsciiString(aNameAttr->Get());
         Handle(XCAFKinematics_PairValueObject) aPairValueObject = aKPairValueAttr->GetObject();
         Handle(StepKinematics_PairValue) aPairValue;
         if (!createKinematicPairValue(aPairValueObject, aPairReprRelationship, aPairValue))
           continue;
         aPairValue->SetName(aNameOfValue);
-        aItems->SetValue(aValueInd, aPairValue);
+        aItems->SetValue(aValueInd++, aPairValue);
       }
       Handle(TCollection_HAsciiString) aNameOfState;
       Handle(TDataStd_Name) aNameAttr;
-      if (aSeqOfStates(aStateInd).FindAttribute(TDataStd_Name::GetID(), aNameAttr))
+      if (anItState.Value().FindAttribute(TDataStd_Name::GetID(), aNameAttr))
         aNameOfState = new TCollection_HAsciiString(aNameAttr->Get());
       aStateRepr->Init(aNameOfState, aItems, aMechanism->ContextOfItems(), aMechanism);
       Model->AddWithRefs(aStateRepr);
index f623e2afbdc343cc6d6159d112a9d075140bc819..b0eba23c0c960969bcdc8bfcbe3bd425e1bd6b2b 100644 (file)
 #include <StepBasic_ConversionBasedUnitAndPlaneAngleUnit.hxx>
 #include <StepBasic_SiUnitAndPlaneAngleUnit.hxx>
 #include <StepRepr_GlobalUnitAssignedContext.hxx>
+#include <STEPConstruct_UnitContext.hxx>
 #include <UnitsMethods.hxx>
 
 //=============================================================================
@@ -228,7 +229,7 @@ Handle(Geom_Axis2Placement) StepToGeom::MakeAxis2Placement(const Handle(StepKine
   const gp_Dir Ngp (anAsisX,anAxisY,anAxisZ);
   const gp_Dir Vxgp(aDirX, aDirY, aDirZ);
   gp_Ax2 gpAx2 = gp_Ax2(Pgp, Ngp, Vxgp);
-    return new Geom_Axis2Placement(gpAx2);
+  return new Geom_Axis2Placement(gpAx2);
 }
 
 //=============================================================================
@@ -2081,226 +2082,180 @@ Handle(TColStd_HArray1OfReal) StepToGeom::MakeYprRotation(const StepKinematics_S
       SR.YprRotation()->Length() == 3)
   {
     anYPRRotation = SR.YprRotation();
+    return anYPRRotation;
   }
+
+  if (SR.RotationAboutDirection().IsNull() ||
+      SR.RotationAboutDirection()->DirectionOfAxis()->DirectionRatios()->Length() != 3 ||
+      theCntxt.IsNull())
+    return NULL;
   //rotation is a rotation_about_direction
-  else if (!SR.RotationAboutDirection().IsNull() &&
-           SR.RotationAboutDirection()->DirectionOfAxis()->DirectionRatios()->Length() == 3 &&
-           !theCntxt.IsNull())
+  Handle(Geom_Direction) anAxis;
+  anAxis = new Geom_Direction(SR.RotationAboutDirection()->DirectionOfAxis()->DirectionRatiosValue(1),
+    SR.RotationAboutDirection()->DirectionOfAxis()->DirectionRatiosValue(2),
+    SR.RotationAboutDirection()->DirectionOfAxis()->DirectionRatiosValue(3));
+  Standard_Real anAngle = SR.RotationAboutDirection()->RotationAngle();
+  if (Abs(anAngle) < Precision::Angular())
   {
-    Handle(Geom_Direction) anAxis;
-    anAxis = new Geom_Direction(SR.RotationAboutDirection()->DirectionOfAxis()->DirectionRatiosValue(1),
-                                SR.RotationAboutDirection()->DirectionOfAxis()->DirectionRatiosValue(2),
-                                SR.RotationAboutDirection()->DirectionOfAxis()->DirectionRatiosValue(3));
-    Standard_Real anAngle = SR.RotationAboutDirection()->RotationAngle();
-    if (anAngle == 0.)
-    {
-      // a zero rotation is converted trivially
-      anYPRRotation = new TColStd_HArray1OfReal(1, 3);
-      anYPRRotation->SetValue(1, 0.);
-      anYPRRotation->SetValue(2, 0.);
-      anYPRRotation->SetValue(3, 0.);
-      return anYPRRotation;
-    }
-    Standard_Real dx = anAxis->X();
-    Standard_Real dy = anAxis->Y();
-    Standard_Real dz = anAxis->Z();
-    NCollection_Sequence<Handle(StepBasic_NamedUnit)> aPaUnits;
-    for (Standard_Integer anInd = 1; anInd <= theCntxt->Units()->Length(); ++anInd)
-    {
-      if (theCntxt->UnitsValue(anInd)->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndPlaneAngleUnit))||
-          theCntxt->UnitsValue(anInd)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndPlaneAngleUnit)))
-          aPaUnits.Append(theCntxt->UnitsValue(anInd));
-    }
-    if (aPaUnits.Length() != 1)
-      return anYPRRotation;
-    Handle(StepBasic_NamedUnit) aPau = aPaUnits.Value(1);
-    while (!aPau.IsNull() && aPau->IsKind((STANDARD_TYPE(StepBasic_ConversionBasedUnitAndPlaneAngleUnit))))
-    {
-      Handle(StepBasic_ConversionBasedUnitAndPlaneAngleUnit) aConverUnit = Handle(StepBasic_ConversionBasedUnitAndPlaneAngleUnit)::DownCast(aPau);
-      anAngle = anAngle * aConverUnit->ConversionFactor()->ValueComponent();
-      aPau = aConverUnit->ConversionFactor()->UnitComponent().NamedUnit();
-    }
-    if(aPau.IsNull())
-      return anYPRRotation;
-    Handle(StepBasic_SiUnitAndPlaneAngleUnit) aSiUnit = Handle(StepBasic_SiUnitAndPlaneAngleUnit)::DownCast(aPau);
-    if(aSiUnit.IsNull() || aSiUnit->Name() != StepBasic_SiUnitName::StepBasic_sunRadian)
-      return anYPRRotation;
-    switch (aSiUnit->Prefix())
-    {
-    case(StepBasic_spExa):
-      anAngle = 1.E18 * anAngle;
-      break;
-    case(StepBasic_spPeta):
-      anAngle = 1.E15 * anAngle;
-      break;
-    case(StepBasic_spTera):
-      anAngle = 1.E12 * anAngle;
-      break;
-    case(StepBasic_spGiga):
-      anAngle = 1.E9 * anAngle;
-      break;
-    case(StepBasic_spMega):
-      anAngle = 1.E6 * anAngle;
-      break;
-    case(StepBasic_spKilo):
-      anAngle = 1.E3 * anAngle;
-      break;
-    case(StepBasic_spHecto):
-      anAngle = 1.E2 * anAngle;
-      break;
-    case(StepBasic_spDeca):
-      anAngle = 1.E1 * anAngle;
-      break;
-    case(StepBasic_spDeci):
-      anAngle = 1.E-1 * anAngle;
-      break;
-    case(StepBasic_spCenti):
-      anAngle = 1.E-2 * anAngle;
-      break;
-    case(StepBasic_spMilli):
-      anAngle = 1.E-3 * anAngle;
-      break;
-    case(StepBasic_spMicro):
-      anAngle = 1.E-6 * anAngle;
-      break;
-    case(StepBasic_spNano):
-      anAngle = 1.E-9 * anAngle;
-      break;
-    case(StepBasic_spPico):
-      anAngle = 1.E-12 * anAngle;
-      break;
-    case(StepBasic_spFemto):
-      anAngle = 1.E-15 * anAngle;
-      break;
-    case(StepBasic_spAtto):
-      anAngle = 1.E-18 * anAngle;
-      break;
-    }
-    Standard_Real anUcf = SR.RotationAboutDirection()->RotationAngle() / anAngle;
-    Standard_Real aSA = Sin(anAngle);
-    Standard_Real aCA = Cos(anAngle);
-    Standard_Real aYaw = 0, aPitch = 0, aRoll = 0;
-    // axis parallel either to x-axis or to z-axis?
-    if (dy == 0. && dx * dz == 0.)
-    {
-      while (anAngle <= -M_PI)
-        anAngle = anAngle + 2 * M_PI;
-      while (anAngle > M_PI)
-        anAngle = anAngle - 2 * M_PI;
-
-      aYaw = anUcf * anAngle;
-      if (anAngle != M_PI)
-        aRoll = -aYaw;
+    // a zero rotation is converted trivially
+    anYPRRotation = new TColStd_HArray1OfReal(1, 3);
+    anYPRRotation->SetValue(1, 0.);
+    anYPRRotation->SetValue(2, 0.);
+    anYPRRotation->SetValue(3, 0.);
+    return anYPRRotation;
+  }
+  Standard_Real dx = anAxis->X();
+  Standard_Real dy = anAxis->Y();
+  Standard_Real dz = anAxis->Z();
+  NCollection_Sequence<Handle(StepBasic_NamedUnit)> aPaUnits;
+  for (Standard_Integer anInd = 1; anInd <= theCntxt->Units()->Length(); ++anInd)
+  {
+    if (theCntxt->UnitsValue(anInd)->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndPlaneAngleUnit)) ||
+      theCntxt->UnitsValue(anInd)->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndPlaneAngleUnit)))
+      aPaUnits.Append(theCntxt->UnitsValue(anInd));
+  }
+  if (aPaUnits.Length() != 1)
+    return anYPRRotation;
+  Handle(StepBasic_NamedUnit) aPau = aPaUnits.Value(1);
+  while (!aPau.IsNull() && aPau->IsKind((STANDARD_TYPE(StepBasic_ConversionBasedUnitAndPlaneAngleUnit))))
+  {
+    Handle(StepBasic_ConversionBasedUnitAndPlaneAngleUnit) aConverUnit = Handle(StepBasic_ConversionBasedUnitAndPlaneAngleUnit)::DownCast(aPau);
+    anAngle = anAngle * aConverUnit->ConversionFactor()->ValueComponent();
+    aPau = aConverUnit->ConversionFactor()->UnitComponent().NamedUnit();
+  }
+  if (aPau.IsNull())
+    return anYPRRotation;
+  Handle(StepBasic_SiUnitAndPlaneAngleUnit) aSiUnit = Handle(StepBasic_SiUnitAndPlaneAngleUnit)::DownCast(aPau);
+  if (aSiUnit.IsNull() || aSiUnit->Name() != StepBasic_SiUnitName::StepBasic_sunRadian)
+    return anYPRRotation;
+  anAngle = (!aSiUnit->HasPrefix() ?
+             1. : STEPConstruct_UnitContext::ConvertSiPrefix(aSiUnit->Prefix())) * anAngle;
+  Standard_Real anUcf = SR.RotationAboutDirection()->RotationAngle() / anAngle;
+  Standard_Real aSA = Sin(anAngle);
+  Standard_Real aCA = Cos(anAngle);
+  Standard_Real aYaw = 0, aPitch = 0, aRoll = 0;
+
+  // axis parallel either to x-axis or to z-axis?
+  if (Abs(dy) < Precision::Confusion() && Abs(dx * dz) < Precision::SquareConfusion())
+  {
+    while (anAngle <= -M_PI)
+      anAngle = anAngle + 2 * M_PI;
+    while (anAngle > M_PI)
+      anAngle = anAngle - 2 * M_PI;
+
+    aYaw = anUcf * anAngle;
+    if (Abs(anAngle - M_PI) >= Precision::Angular())
+      aRoll = -aYaw;
+    else
+      aRoll = aYaw;
+    anYPRRotation = new TColStd_HArray1OfReal(1, 3);
+    anYPRRotation->SetValue(1, 0.);
+    anYPRRotation->SetValue(2, 0.);
+    anYPRRotation->SetValue(3, 0.);
+    if (dx != 0.)
+      if (dx > 0.)
+        anYPRRotation->SetValue(3, aYaw);
       else
-        aRoll = aYaw;
-      anYPRRotation = new TColStd_HArray1OfReal(1, 3);
-      anYPRRotation->SetValue(1, 0.);
-      anYPRRotation->SetValue(2, 0.);
-      anYPRRotation->SetValue(3, 0.);
-      if (dx != 0.)
-        if (dx > 0.)
-          anYPRRotation->SetValue(3, aYaw);
-        else
-          anYPRRotation->SetValue(3, aRoll);
+        anYPRRotation->SetValue(3, aRoll);
+    else
+      if (dz > 0.)
+        anYPRRotation->SetValue(1, aYaw);
       else
-        if (dz > 0.)
-          anYPRRotation->SetValue(1, aYaw);
-        else
-          anYPRRotation->SetValue(1, aRoll);
-      return anYPRRotation;
-    }
+        anYPRRotation->SetValue(1, aRoll);
+    return anYPRRotation;
+  }
 
-    // axis parallel to y-axis - use y-axis as pitch axis
-    if ((dy != 0.0) && (dx == 0.0) && (dz == 0.0))
-    {
-      if (aCA >= 0.0)
-      {
-        aYaw = 0.0;
-        aRoll = 0.0;
-      }
-      else
-      {
-        aYaw = anUcf * M_PI;
-        aRoll = aYaw;
-      }
-      aPitch = anUcf * ATan2(aSA, Abs(aCA));
-      if (dy < 0.0)
-        aPitch = -aPitch;
-      anYPRRotation = new TColStd_HArray1OfReal(1, 3);
-      anYPRRotation->SetValue(1, aYaw);
-      anYPRRotation->SetValue(2, aPitch);
-      anYPRRotation->SetValue(3, aRoll);
-      return anYPRRotation;
-    }
-     // axis not parallel to any axis of coordinate system
-     // compute rotation matrix
-    Standard_Real aCm1 = 1 - aCA;
-
-    Standard_Real aRotMat[3][3] = { { dx * dx * aCm1 + aCA ,dx * dy * aCm1 - dz * aSA, dx * dz * aCm1 + dy * aSA },
-                                    { dx * dy * aCm1 + dz * aSA,dy * dy * aCm1 + aCA, dy * dz * aCm1 - dx * aSA },
-                                    { dx * dz * aCm1 - dy * aSA, dy * dz * aCm1 + dx * aSA,dz * dz * aCm1 + aCA } };
-
-    // aRotMat[1][3] equals SIN(pitch_angle)
-    if (Abs(aRotMat[0][2] == 1.))
+  // axis parallel to y-axis - use y-axis as pitch axis
+  if (Abs(dy) >= Precision::Confusion() && Abs(dx) < Precision::Confusion() && Abs(dz) < Precision::Confusion())
+  {
+    if (aCA >= 0.)
     {
-      // |aPithc| = PI/2
-      if (aRotMat[0][2] == 1.)
-        aPitch = M_PI_2;
-      else
-        aPitch = -M_PI_2;
-      // In this case, only the sum or difference of roll and yaw angles
-      // is relevant and can be evaluated from the matrix.
-      // According to IP `rectangular pitch angle' for ypr_rotation,
-      // the roll angle is set to zero.
-      aRoll = 0.;
-      aYaw = ATan2(aRotMat[1][0], aRotMat[1][1]);
-      // result of ATAN is in the range[-PI / 2, PI / 2].
-      // Here all four quadrants are needed.
-
-      if (aRotMat[1][1] < 0.)
-        if (aYaw <= 0.)
-          aYaw = aYaw + M_PI;
-        else
-          aYaw = aYaw - M_PI;
+      aYaw = 0.0;
+      aRoll = 0.0;
     }
     else
     {
-      // COS (pitch_angle) not equal to zero
-      aYaw = ATan2(-aRotMat[0][1], aRotMat[0][0]);
-
-      if (aRotMat[0][0] < 0.)
-      {
-        if (aYaw <= 0.)
-          aYaw = aYaw + M_PI;
-        else
-          aYaw = aYaw - M_PI;
-      }
-      Standard_Real aSY = Sin(aYaw);
-      Standard_Real aCY = Cos(aYaw);
-      Standard_Real aSR = Sin(aRoll);
-      Standard_Real aCR = Cos(aRoll);
-
-      if (Abs(aSY) > Abs(aCY) &&
-          Abs(aSY) > Abs(aSR) &&
-          Abs(aSY) > Abs(aCR))
-        aCm1 = -aRotMat[0][1] / aSY;
-      else
-        if (Abs(aCY) > Abs(aSR) && Abs(aCY) > Abs(aCR))
-          aCm1 = aRotMat[0][0] / aCY;
-        else
-          if (Abs(aSR) > Abs(aCR))
-            aCm1 = -aRotMat[1][2] / aSR;
-          else
-            aCm1 = aRotMat[2][2] / aCR;
-      aPitch = ATan2(aRotMat[0][2], aCm1);
-    }
-    aYaw = aYaw * anUcf;
-    aPitch = aPitch * anUcf;
-    aRoll = aRoll * anUcf;
+      aYaw = anUcf * M_PI;
+      aRoll = aYaw;
+    }
+    aPitch = anUcf * ATan2(aSA, Abs(aCA));
+    if (dy < 0.)
+      aPitch = -aPitch;
     anYPRRotation = new TColStd_HArray1OfReal(1, 3);
     anYPRRotation->SetValue(1, aYaw);
     anYPRRotation->SetValue(2, aPitch);
     anYPRRotation->SetValue(3, aRoll);
+    return anYPRRotation;
+  }
+  // axis not parallel to any axis of coordinate system
+  // compute rotation matrix
+  Standard_Real aCm1 = 1 - aCA;
+
+  Standard_Real aRotMat[3][3] = { { dx * dx * aCm1 + aCA ,dx * dy * aCm1 - dz * aSA, dx * dz * aCm1 + dy * aSA },
+                                  { dx * dy * aCm1 + dz * aSA,dy * dy * aCm1 + aCA, dy * dz * aCm1 - dx * aSA },
+                                  { dx * dz * aCm1 - dy * aSA, dy * dz * aCm1 + dx * aSA,dz * dz * aCm1 + aCA } };
+
+  // aRotMat[1][3] equals SIN(pitch_angle)
+  if (Abs(Abs(aRotMat[0][2] - 1.)) < Precision::Confusion())
+  {
+    // |aPitch| = PI/2
+    if (Abs(aRotMat[0][2] - 1.) < Precision::Confusion())
+      aPitch = M_PI_2;
+    else
+      aPitch = -M_PI_2;
+    // In this case, only the sum or difference of roll and yaw angles
+    // is relevant and can be evaluated from the matrix.
+    // According to IP `rectangular pitch angle' for ypr_rotation,
+    // the roll angle is set to zero.
+    aRoll = 0.;
+    aYaw = ATan2(aRotMat[1][0], aRotMat[1][1]);
+    // result of ATAN is in the range[-PI / 2, PI / 2].
+    // Here all four quadrants are needed.
+
+    if (aRotMat[1][1] < 0.)
+      if (aYaw <= 0.)
+        aYaw = aYaw + M_PI;
+      else
+        aYaw = aYaw - M_PI;
   }
+  else
+  {
+    // COS (pitch_angle) not equal to zero
+    aYaw = ATan2(-aRotMat[0][1], aRotMat[0][0]);
+
+    if (aRotMat[0][0] < 0.)
+    {
+      if (aYaw < 0. || Abs(aYaw) < Precision::Angular())
+        aYaw = aYaw + M_PI;
+      else
+        aYaw = aYaw - M_PI;
+    }
+    Standard_Real aSY = Sin(aYaw);
+    Standard_Real aCY = Cos(aYaw);
+    Standard_Real aSR = Sin(aRoll);
+    Standard_Real aCR = Cos(aRoll);
+
+    if (Abs(aSY) > Abs(aCY) &&
+        Abs(aSY) > Abs(aSR) &&
+        Abs(aSY) > Abs(aCR))
+      aCm1 = -aRotMat[0][1] / aSY;
+    else
+      if (Abs(aCY) > Abs(aSR) && Abs(aCY) > Abs(aCR))
+        aCm1 = aRotMat[0][0] / aCY;
+      else
+        if (Abs(aSR) > Abs(aCR))
+          aCm1 = -aRotMat[1][2] / aSR;
+        else
+          aCm1 = aRotMat[2][2] / aCR;
+    aPitch = ATan2(aRotMat[0][2], aCm1);
+  }
+  aYaw = aYaw * anUcf;
+  aPitch = aPitch * anUcf;
+  aRoll = aRoll * anUcf;
+  anYPRRotation = new TColStd_HArray1OfReal(1, 3);
+  anYPRRotation->SetValue(1, aYaw);
+  anYPRRotation->SetValue(2, aPitch);
+  anYPRRotation->SetValue(3, aRoll);
+
   return anYPRRotation;
 }
index a9b6f2edba9b5f3c74a7fb67afca19a3a6121f0a..a2a71f64ef5789aa6e5a56602bc3c604858d0ec4 100644 (file)
@@ -337,6 +337,10 @@ const Standard_GUID& XCAFDoc::KinematicRefLink2GUID()
   return ID;
 }
 
+//=======================================================================
+//function : KinematicRefJointGUID
+//purpose  : 
+//=======================================================================
 Standard_EXPORT const Standard_GUID& XCAFDoc::KinematicRefJointGUID()
 {
   static const Standard_GUID ID("596B048C-A965-4514-A059-464560BFAE4E");
index 49da1784c0762743a7f27aad861f5a306f3f963b..8e0cc9997200aafca95ba22a24d967777578cb85 100644 (file)
@@ -47,7 +47,6 @@ enum ChildLab
   ChildLab_SecondTrsf,
   ChildLab_FirstGeomParam,
   ChildLab_SecondGeomParam,
-  ChildLab_Value
 };
 
 //=======================================================================
@@ -118,7 +117,7 @@ void XCAFDoc_KinematicPair::SetObject(const Handle(XCAFKinematics_PairObject)& t
   TDataXtd_Plane::Set(Label().FindChild(ChildLab_FirstTrsf), gp_Pln(theObject->FirstTransformation()));
   TDataXtd_Plane::Set(Label().FindChild(ChildLab_SecondTrsf), gp_Pln(theObject->SecondTransformation()));
 
-  if (!theObject->GetAllLimits().IsNull() && theObject->HasLimits()) {
+  if (theObject->HasLimits()) {
     Handle(TDataStd_RealArray) aLimitsAttr;
     aLimitsAttr = TDataStd_RealArray::Set(Label(), getLimitsID(), 1, theObject->GetAllLimits()->Length());
     aLimitsAttr->ChangeArray(theObject->GetAllLimits());
@@ -137,7 +136,7 @@ void XCAFDoc_KinematicPair::SetObject(const Handle(XCAFKinematics_PairObject)& t
       theObject->Type() <= XCAFKinematics_PairType_LinearFlexibleAndPinion) {
     Handle(XCAFKinematics_LowOrderPairObjectWithCoupling) anObject =
       Handle(XCAFKinematics_LowOrderPairObjectWithCoupling)::DownCast(theObject);
-    if (!anObject->GetAllParams().IsNull() && anObject->GetAllParams()->Upper() > 0) {
+    if (!anObject->GetAllParams().IsNull() && !anObject->GetAllParams()->IsEmpty()) {
       Handle(TDataStd_RealArray) aParamsAttr;
       aParamsAttr = TDataStd_RealArray::Set(Label(), getParamsID(), 1, anObject->GetAllParams()->Upper());
       aParamsAttr->ChangeArray(anObject->GetAllParams());
@@ -186,8 +185,8 @@ void XCAFDoc_KinematicPair::SetObject(const Handle(XCAFKinematics_PairObject)& t
       TNaming_Builder aTNBuild(Label().FindChild(ChildLab_FirstGeomParam));
       aTNBuild.Generated(anEdge);
     }
-    if (anObject->Type() == XCAFKinematics_PairType_SlidingCurve ||
-        anObject->Type() == XCAFKinematics_PairType_RollingCurve)
+    if (anObject->Type() >= XCAFKinematics_PairType_SlidingCurve &&
+        anObject->Type() <= XCAFKinematics_PairType_LinearFlexibleAndPlanarCurve)
     {
       TopoDS_Edge anEdge1, anEdge2;
       if (!anObject->FirstCurve().IsNull()) {
@@ -201,15 +200,6 @@ void XCAFDoc_KinematicPair::SetObject(const Handle(XCAFKinematics_PairObject)& t
         aTNBuild2.Generated(anEdge2);
       }
     }
-    if (anObject->Type() == XCAFKinematics_PairType_LinearFlexibleAndPlanarCurve)
-    {
-      TopoDS_Edge anEdge;
-      if (!anObject->FirstCurve().IsNull()) {
-        aBuilder.MakeEdge(anEdge, anObject->FirstCurve(), Precision::Confusion());
-        TNaming_Builder aTNBuild1(Label().FindChild(ChildLab_FirstGeomParam));
-        aTNBuild1.Generated(anEdge);
-      }
-    }
   }
 }
 
index f5952e33bfb8d773d4f7537a23649d6607cea8f4..bce52988c163f74d4fe267f735dfec735fba3d44 100644 (file)
@@ -61,13 +61,19 @@ Handle(XCAFDoc_KinematicPairValue) XCAFDoc_KinematicPairValue::Set(const TDF_Lab
     theValue.AddAttribute(anAttr);
   }
 
+  // check for exist old reference
   Handle(TDataStd_TreeNode) aJointNode, aValueNode;
+  if (theValue.FindAttribute(XCAFDoc::KinematicRefJointGUID(), aValueNode)) {
+    if (aValueNode->HasFather() && aValueNode->Father()->Label() == theJoint)
+      return anAttr;
+    aValueNode->Remove();
+  }
+
   // Add reference to Joint
   aValueNode = TDataStd_TreeNode::Set(theJoint, XCAFDoc::KinematicRefJointGUID());
   aJointNode = TDataStd_TreeNode::Set(theValue, XCAFDoc::KinematicRefJointGUID());
 
   aValueNode->Append(aJointNode);
-
   return anAttr;
 }
 
index 6d8895f36e5f4acf0c7f223407423d4f316e448f..78fef40bb81e43bc72e4a30b0e82cb86322cfd9f 100644 (file)
@@ -35,10 +35,11 @@ class XCAFDoc_KinematicPairValue;
 DEFINE_STANDARD_HANDLE(XCAFDoc_KinematicPairValue, TDF_Attribute)
 
 //! Attribute to store kinematic pair value.
-//! This parameter is an additional attribute for kinematic pair attribute
+//! This parameter is an additional attribute for kinematic pair attribute,
+//! which characterizes the pair for one of the mechanism states. 
 //! It is prohibited to store inconsistent data:
 //! - to store this attribute without kinematic value attribute
-//! - to store attributes with different types
+//! - to store this attribute not of the same type as the type of the pair
 class XCAFDoc_KinematicPairValue : public TDF_Attribute
 {
 
index 32f31455570d117b201b1c4d744122398edc1b3b..86b9364f918f483ea39a279b5e978a48ce9bddbc 100644 (file)
@@ -231,22 +231,25 @@ Standard_EXPORT Standard_Boolean XCAFDoc_KinematicTool::SetBaseLink(const TDF_La
   if (!IsMechanism(aMechanism))
     return Standard_False;
   TDF_LabelSequence aLinks = GetLinks(aMechanism);
-  for (Standard_Integer anInd = 1; anInd <= aLinks.Length(); ++anInd)
+  for (TDF_LabelSequence::Iterator anIt(aLinks); anIt.More(); anIt.Next())
   {
     Handle(TDataStd_Integer) aBase;
-    if (aLinks(anInd).FindAttribute(TDataStd_Integer::GetID(), aBase))
+    if (anIt.Value().FindAttribute(TDataStd_Integer::GetID(), aBase))
     {
-      aLinks(anInd).ForgetAttribute(aBase);
+      anIt.Value().ForgetAttribute(aBase);
       Handle(TDataStd_Name) aLinkName;
-      if (aLinks(anInd).FindAttribute(TDataStd_Name::GetID(), aLinkName) && !aLinkName->Get().IsDifferent("Base"))
+      if (anIt.Value().FindAttribute(TDataStd_Name::GetID(), aLinkName) && !aLinkName->Get().IsDifferent("Base"))
       {
         TCollection_AsciiString aName = "Link ";
-        aName.AssignCat(TCollection_AsciiString(aLinks(anInd).Tag()));
-        TDataStd_Name::Set(aLinks(anInd), aName);
+        aName.AssignCat(TCollection_AsciiString(anIt.Value().Tag()));
+        TDataStd_Name::Set(anIt.Value(), aName);
       }
     }
   }
-  TDataStd_Name::Set(theLink, "Base");
+  Handle(TDataStd_Name) aLinkName;
+  if (!theLink.FindAttribute(TDataStd_Name::GetID(), aLinkName) ||
+     (!aLinkName.IsNull() && !aLinkName->Get().IsDifferent("Link " + theLink.Tag())))
+    TDataStd_Name::Set(theLink, "Base");
   TDataStd_Integer::Set(theLink, 1);
 }
 
@@ -371,9 +374,6 @@ Standard_Boolean XCAFDoc_KinematicTool::SetJoint(const TDF_Label& theJoint,
   aJointNode->Remove(); // fix against bug in TreeNode::Append()
   aLinkNode->Append(aJointNode);
 
-  TCollection_AsciiString aName = "Joint ";
-  aName.AssignCat(TCollection_AsciiString(theJoint.Tag()));
-  TDataStd_Name::Set(theJoint, aName);
   return Standard_True;
 }
 
@@ -396,12 +396,6 @@ void XCAFDoc_KinematicTool::RemoveJoint(const TDF_Label& theJoint)
 
 }
 
-Standard_Boolean XCAFDoc_KinematicTool::IsValue(const TDF_Label& theValue) const
-{
-  Handle(XCAFDoc_KinematicPairValue) anAttr;
-  return theValue.FindAttribute(XCAFDoc_KinematicPairValue::GetID(), anAttr);
-}
-
 //=======================================================================
 //function : GetMechanisms
 //purpose  : 
@@ -532,19 +526,37 @@ TDF_Label XCAFDoc_KinematicTool::AddState(const TDF_Label& theMechanism)
   return aState;
 }
 
+//=======================================================================
+//function : IsState
+//purpose  : 
+//=======================================================================
+Standard_Boolean XCAFDoc_KinematicTool::IsState(const TDF_Label& theState) const
+{
+  return IsMechanism(theState.Father().Father()) && theState.Father().Tag() == 3;
+}
+
 //=======================================================================
 //function : AddValue
 //purpose  : 
 //=======================================================================
 TDF_Label XCAFDoc_KinematicTool::AddValue(const TDF_Label& theState)
 {
-  if(!IsMechanism(theState.Father().Father()) &&
-     theState.Father().Tag() != 3)
+  if (!IsState(theState))
     return TDF_Label();
 
   return theState.NewChild();
 }
 
+//=======================================================================
+//function : IsValue
+//purpose  : 
+//=======================================================================
+Standard_Boolean XCAFDoc_KinematicTool::IsValue(const TDF_Label& theValue) const
+{
+  Handle(XCAFDoc_KinematicPairValue) anAttr;
+  return theValue.FindAttribute(XCAFDoc_KinematicPairValue::GetID(), anAttr);
+}
+
 //=======================================================================
 //function : RemoveValue
 //purpose  : 
@@ -573,7 +585,7 @@ TDF_LabelSequence XCAFDoc_KinematicTool::GetStates(const TDF_Label& theMechanism
     return aStatesArray;
 
   TDF_Label aRootOfState = getRootOfStates(theMechanism);
-  if (!IsMechanism(theMechanism) || aRootOfState.IsNull())
+  if (aRootOfState.IsNull())
     return aStatesArray;
 
   for (TDF_ChildIterator anIt(aRootOfState); anIt.More(); anIt.Next()) {
@@ -604,7 +616,7 @@ TDF_Label XCAFDoc_KinematicTool::GetStateOfValue(const TDF_Label& theValue) cons
 Standard_EXPORT TDF_LabelSequence XCAFDoc_KinematicTool::GetValuesOfState(const TDF_Label& theState) const
 {
   TDF_LabelSequence aValueArray;
-  if (!IsMechanism(theState.Father().Father()) || theState.Father().Tag() != 3)
+  if (!IsState(theState))
     return aValueArray;
 
   for (TDF_ChildIterator anIt(theState); anIt.More(); anIt.Next()) {
@@ -663,7 +675,7 @@ TDF_LabelSequence XCAFDoc_KinematicTool::GetValuesOfJoint(const TDF_Label& theJo
 void XCAFDoc_KinematicTool::RemoveState(const TDF_Label& theState)
 {
   TDF_Label aMechanism = theState.Father().Father();
-  if (!IsMechanism(aMechanism) || theState.Father().Tag() != 3)
+  if (!IsState(theState))
     return;
   Handle(TDataStd_TreeNode) aNode;
   TDF_LabelSequence aSeqOfValues = GetValuesOfState(theState);
index 847cc13d0d3bcf9d9ce328c3694927909d976e5e..596f672cee552228c8c912f137b9a91f68c53dc0 100644 (file)
@@ -153,6 +153,10 @@ public:
   //! \return created state label
   Standard_EXPORT TDF_Label AddState(const TDF_Label& theMechanism);
 
+  //! Checks is the given label a State
+  //! \return the result of check
+  Standard_EXPORT Standard_Boolean IsState(const TDF_Label& theState) const;
+
   //! Adds new empty label for Value.
   //! \param[in] theState parent state
   //! \return created value label
index 72346d5e25af93cd272b51a3d53b14883f88d2ae..a8f56a2ec33b5a54a914e7410a52a35501b7aacb 100644 (file)
@@ -36,7 +36,6 @@ DEFINE_STANDARD_HANDLE(XCAFKinematics_HighOrderPairObject, XCAFKinematics_PairOb
 //! - XCAFKinematics_PairType_PointOnPlanarCurve
 //! - XCAFKinematics_PairType_SlidingCurve
 //! - XCAFKinematics_PairType_RollingCurve
-//! - XCAFKinematics_PairType_RollingCurve
 //! - XCAFKinematics_PairType_LinearFlexibleAndPlanarCurve
 class XCAFKinematics_HighOrderPairObject : public XCAFKinematics_PairObject
 {
@@ -66,10 +65,10 @@ public:
 
   Handle(TColStd_HArray1OfReal) GetAllLimits() const Standard_OVERRIDE
   {
-    Handle(TColStd_HArray1OfReal) aLimitArray;
+
     if (HasLimits())
-      aLimitArray = myLimits;
-    return aLimitArray;
+      return myLimits;
+    return NULL;
   }
 
   //! Sets low limit of rotation attribute (only for SlidingSurface and RollingSurface)
@@ -160,10 +159,6 @@ public:
   //! \return curve
   Standard_EXPORT Handle(Geom_Curve) SecondCurve() const;
 
-  //! Sets curve attribute (only for PointOnCurve)
-  //! \param[in] theTrimmedCurve trimmed curve
-  //Standard_EXPORT void SetTrimmedCurve(const Standard_Real& theTrim1, const Standard_Real& theTrim2);
-
   //! Sets trimmed curve attribute (only for PointOnCurve)
   //! \param[in] aTrimCurve trimmed curve
   Standard_EXPORT void SetTrimmedCurve(const Handle(Geom_TrimmedCurve)& aTrimCurve);
@@ -172,15 +167,12 @@ public:
   //! \return trimmed curve
   Standard_EXPORT Handle(Geom_TrimmedCurve) TrimmedCurve() const;
 
-  //! \return trimmed curve
-  //Standard_EXPORT void TrimmedCurve(Standard_Real& theTrim1,Standard_Real& theTrim2) const;
-
   //! Sets surface attribute (only for PointOnSurface)
   //! \param[in] theSurface surface
   Standard_EXPORT void SetSurface(const Handle(Geom_Surface)& theSurface);
 
   //! Gets surface attribute (only for PointOnSurface)
-  //! \return curve
+  //! \return surface
   Standard_EXPORT Handle(Geom_Surface) Surface() const;
 
   //! Sets surface attribute (only for SlidingSurface and RollingSurface)
@@ -199,10 +191,6 @@ public:
   //! \return surface
   Standard_EXPORT Handle(Geom_Surface) SecondSurface() const;
 
-  //! Sets surface attribute (only for PointOnSurface)
-  //! \param[in] theTrimmedSurface trimmed surface
-  //Standard_EXPORT void SetTrimmedSurface(const Standard_Real& U1, const Standard_Real& U2, const Standard_Real& V1, const Standard_Real& V2);
-
   //! Sets trimmed surface attribute (only for PointOnSurface)
   //! \param[in] aTrimSurface trimmered surface
   Standard_EXPORT void SetTrimmedSurface(const Handle(Geom_RectangularTrimmedSurface)& aTrimSurface);
index 6b60427aaa8564688a73340d0ce811a43ebec478..ca8a488ae79c8ec0ecf3261aa79f082c96891643 100644 (file)
@@ -24,19 +24,20 @@ class TColStd_HArray1OfReal;
 DEFINE_STANDARD_HANDLE(XCAFKinematics_LowOrderPairObject, XCAFKinematics_PairObject)
 
 //! \class XCAFKinematics_LowOrderPairObject
-//! \brief Object for low order kinematic pairs:
-//! - XCAFKinematics_PairType_FullyConstrained
-//! - XCAFKinematics_PairType_Revolute
-//! - XCAFKinematics_PairType_Prismatic
-//! - XCAFKinematics_PairType_Cylindrical
-//! - XCAFKinematics_PairType_Universal
-//! - XCAFKinematics_PairType_Homokinetic
-//! - XCAFKinematics_PairType_SphericalWithPin
-//! - XCAFKinematics_PairType_Spherical
-//! - XCAFKinematics_PairType_Planar
-//! - XCAFKinematics_PairType_Unconstrained
-//! Not all limits are used for each pair, if less than 3 translation/rotation
-//! limits is used values should be specified in alphabetical order.
+//! \brief Object for low order kinematic pairs: 
+//! - XCAFKinematics_PairType_FullyConstrained <F, F, F, F, F, F>
+//! - XCAFKinematics_PairType_Revolute         <F, F, T, F, F, F>
+//! - XCAFKinematics_PairType_Prismatic        <F, F, F, T, F, F>
+//! - XCAFKinematics_PairType_Cylindrical      <F, F, T, F, F, T>
+//! - XCAFKinematics_PairType_Universal        <T, F, T, F, F, F>
+//! - XCAFKinematics_PairType_Homokinetic      <T, F, T, F, F, F>
+//! - XCAFKinematics_PairType_SphericalWithPin <F, T, T, F, F, F>
+//! - XCAFKinematics_PairType_Spherical        <T, T, T, F, F, F>
+//! - XCAFKinematics_PairType_Planar           <T, F, F, T, T, F>
+//! - XCAFKinematics_PairType_Unconstrained    <T, T, T, T, T, T>
+//! Not all limits are used for each pair, 
+//! values should be specified in alphabetical order: <rX, rY, rZ, tX, tY, tZ>
+
 class XCAFKinematics_LowOrderPairObject : public XCAFKinematics_PairObject
 {
 
index 0c6682d31c0bea1a86a0e1ef9c7a06a8a451d824..972ff53840727e315b5f17b2b9b0e465866122f0 100644 (file)
@@ -47,8 +47,8 @@ void XCAFKinematics_PairValueObject::SetType(const XCAFKinematics_PairType theTy
   Standard_Integer aNbParams = 0;
   switch (myType) {
   case XCAFKinematics_PairType_Revolute:
-      aNbParams = 1;
-      break;
+    aNbParams = 1;
+    break;
   case XCAFKinematics_PairType_Prismatic:
     aNbParams = 1;
     break;
index 84d6b1d19735acaf6ce550fda7a09c3c5860f6f3..a93b8a57cf4e31523cd9072189fdf644448401c3 100644 (file)
@@ -1123,6 +1123,9 @@ static Standard_Integer XAttributeValue (Draw_Interpretor& di, Standard_Integer
     else if (att->ID() == XCAFDoc::KinematicRefLink1GUID() || att->ID() == XCAFDoc::KinematicRefLink2GUID()){
       type = "Kinematic Joint to Link";
     }
+    else if (att->ID() == XCAFDoc::KinematicRefJointGUID()) {
+      type = "Kinematic Value to Joint";
+    }
     else return 0;
 
     Handle(XCAFDoc_GraphNode) DETGN = Handle(XCAFDoc_GraphNode)::DownCast(att);
index 3f39ec92c7ea4655169df8376540a60edf8d20c0..6660099750f43ca9e2f1d8bc2b93eef8e1c44381 100644 (file)
@@ -512,11 +512,11 @@ static Standard_Integer getLinksOfJoint(Draw_Interpretor& di, Standard_Integer a
   if (!getDocument(di, argv[1], aDoc))
     return 1;
 
+  Handle(XCAFDoc_KinematicTool) aTool = XCAFDoc_DocumentTool::KinematicTool(aDoc->Main());
   TDF_Label aJoint;
-  if (!getLabel(di, aDoc, argv[2], aJoint))
+  if (!getLabel(di, aDoc, argv[2], aJoint) || !aTool->IsJoint(aJoint))
     return 1;
 
-  Handle(XCAFDoc_KinematicTool) aTool = XCAFDoc_DocumentTool::KinematicTool(aDoc->Main());
   TDF_Label aLink1, aLink2;
   aTool->GetLinksOfJoint(aJoint, aLink1, aLink2);
 
@@ -598,7 +598,7 @@ static Standard_Integer setName(Draw_Interpretor& di, Standard_Integer argc, con
 
   Handle(XCAFDoc_KinematicTool) aTool = XCAFDoc_DocumentTool::KinematicTool(aDoc->Main());
   TDF_Label aJoint;
-  if (!getLabel(di, aDoc, argv[2], aJoint) || !aTool->IsJoint(aJoint))
+  if (!getLabel(di, aDoc, argv[2], aJoint))
     return 1;
 
   TCollection_AsciiString aName;
@@ -610,12 +610,15 @@ static Standard_Integer setName(Draw_Interpretor& di, Standard_Integer argc, con
   }
 
   Handle(XCAFDoc_KinematicPair) aPair;
-  if (aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair)) {
-    Handle(XCAFKinematics_PairObject) anObject = aPair->GetObject();
-    anObject->SetName(aName);
-    aPair->SetObject(anObject);
+  if (!aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair)) {
+    di << "Invalid kinematic pair object\n";
+    return 1;
   }
 
+  Handle(XCAFKinematics_PairObject) anObject = aPair->GetObject();
+  anObject->SetName(aName);
+  aPair->SetObject(anObject);
+
   return 0;
 }
 
@@ -636,15 +639,18 @@ static Standard_Integer getName(Draw_Interpretor& di, Standard_Integer argc, con
 
   Handle(XCAFDoc_KinematicTool) aTool = XCAFDoc_DocumentTool::KinematicTool(aDoc->Main());
   TDF_Label aJoint;
-  if (!getLabel(di, aDoc, argv[2], aJoint) || !aTool->IsJoint(aJoint))
+  if (!getLabel(di, aDoc, argv[2], aJoint))
     return 1;
 
   Handle(XCAFDoc_KinematicPair) aPair;
-  if (aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair)) {
-    Handle(XCAFKinematics_PairObject) anObject = aPair->GetObject();
-    di << anObject->Name();
+  if (!aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair)) {
+    di << "Invalid kinematic pair object\n";
+    return 1;
   }
 
+  Handle(XCAFKinematics_PairObject) anObject = aPair->GetObject();
+  di << anObject->Name();
+
   return 0;
 }
 
@@ -665,26 +671,29 @@ static Standard_Integer setType(Draw_Interpretor& di, Standard_Integer argc, con
 
   Handle(XCAFDoc_KinematicTool) aTool = XCAFDoc_DocumentTool::KinematicTool(aDoc->Main());
   TDF_Label aJoint;
-  if (!getLabel(di, aDoc, argv[2], aJoint) || !aTool->IsJoint(aJoint))
+  if (!getLabel(di, aDoc, argv[2], aJoint))
     return 1;
 
   Handle(XCAFDoc_KinematicPair) aPair;
-  if (aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair)) {
-    Handle(XCAFKinematics_PairObject) anObject = aPair->GetObject();
-    int aType = Draw::Atoi(argv[3]);
-    if (aType >= XCAFKinematics_PairType_FullyConstrained &&
-        aType <= XCAFKinematics_PairType_Unconstrained)
-      anObject = new XCAFKinematics_LowOrderPairObject();
-    else if (aType >= XCAFKinematics_PairType_Screw &&
-             aType <= XCAFKinematics_PairType_LinearFlexibleAndPinion)
-      anObject = new XCAFKinematics_LowOrderPairObjectWithCoupling();
-    else if (aType >= XCAFKinematics_PairType_PointOnSurface &&
-             aType <= XCAFKinematics_PairType_LinearFlexibleAndPlanarCurve)
-      anObject = new XCAFKinematics_HighOrderPairObject();
-    anObject->SetType((XCAFKinematics_PairType)aType);
-    aPair->SetObject(anObject);
+  if (!aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair)) {
+    di << "Invalid kinematic pair object\n";
+    return 1;
   }
 
+  Handle(XCAFKinematics_PairObject) anObject = aPair->GetObject();
+  int aType = Draw::Atoi(argv[3]);
+  if (aType >= XCAFKinematics_PairType_FullyConstrained &&
+      aType <= XCAFKinematics_PairType_Unconstrained)
+    anObject = new XCAFKinematics_LowOrderPairObject();
+  else if (aType >= XCAFKinematics_PairType_Screw &&
+           aType <= XCAFKinematics_PairType_LinearFlexibleAndPinion)
+    anObject = new XCAFKinematics_LowOrderPairObjectWithCoupling();
+  else if (aType >= XCAFKinematics_PairType_PointOnSurface &&
+           aType <= XCAFKinematics_PairType_LinearFlexibleAndPlanarCurve)
+    anObject = new XCAFKinematics_HighOrderPairObject();
+  anObject->SetType((XCAFKinematics_PairType)aType);
+  aPair->SetObject(anObject);
+
   return 0;
 }
 
@@ -705,15 +714,18 @@ static Standard_Integer getType(Draw_Interpretor& di, Standard_Integer argc, con
 
   Handle(XCAFDoc_KinematicTool) aTool = XCAFDoc_DocumentTool::KinematicTool(aDoc->Main());
   TDF_Label aJoint;
-  if (!getLabel(di, aDoc, argv[2], aJoint) || !aTool->IsJoint(aJoint))
+  if (!getLabel(di, aDoc, argv[2], aJoint))
     return 1;
 
   Handle(XCAFDoc_KinematicPair) aPair;
-  if (aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair)) {
-    Handle(XCAFKinematics_PairObject) anObject = aPair->GetObject();
-    di << anObject->Type();
+  if (!aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair)) {
+    di << "Invalid kinematic pair object\n";
+    return 1;
   }
 
+  Handle(XCAFKinematics_PairObject) anObject = aPair->GetObject();
+  di << anObject->Type();
+
   return 0;
 }
 
@@ -734,30 +746,34 @@ static Standard_Integer setTrsf(Draw_Interpretor& di, Standard_Integer argc, con
 
   Handle(XCAFDoc_KinematicTool) aTool = XCAFDoc_DocumentTool::KinematicTool(aDoc->Main());
   TDF_Label aJoint;
-  if (!getLabel(di, aDoc, argv[2], aJoint) || !aTool->IsJoint(aJoint))
+  if (!getLabel(di, aDoc, argv[2], aJoint))
     return 1;
 
   Handle(XCAFDoc_KinematicPair) aPair;
-  if (aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair)) {
-    Handle(XCAFKinematics_PairObject) anObject = aPair->GetObject();
-    Standard_Integer aTrsfNb = Draw::Atoi(argv[3]);
-    Handle(Geom_Plane) aSurface = Handle(Geom_Plane)::DownCast(DrawTrSurf::GetSurface(argv[4]));
-    if (aSurface.IsNull()) {
-      di << "Invalid transformation\n";
-      return 1;
-    }
-    switch (aTrsfNb) {
-    case 1: anObject->SetFirstTransformation(aSurface->Position());
-      break;
-    case 2: anObject->SetSecondTransformation(aSurface->Position());
-      break;
-    default:
-      di << "Invalid number of transformation\n";
-      return 1;
-    }
-    aPair->SetObject(anObject);
+  if (!aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair)) {
+    di << "Invalid kinematic pair object\n";
+    return 1;
   }
 
+  Handle(XCAFKinematics_PairObject) anObject = aPair->GetObject();
+  Standard_Integer aTrsfNb = Draw::Atoi(argv[3]);
+  Handle(Geom_Plane) aSurface = Handle(Geom_Plane)::DownCast(DrawTrSurf::GetSurface(argv[4]));
+  if (aSurface.IsNull()) {
+    di << "Invalid transformation\n";
+    return 1;
+  }
+  switch (aTrsfNb) {
+  case 1: anObject->SetFirstTransformation(aSurface->Position());
+    break;
+  case 2: anObject->SetSecondTransformation(aSurface->Position());
+    break;
+  default:
+    di << "Invalid number of transformation\n";
+    return 1;
+  }
+  aPair->SetObject(anObject);
+
+
   return 0;
 }
 
@@ -778,23 +794,26 @@ static Standard_Integer getTrsf(Draw_Interpretor& di, Standard_Integer argc, con
 
   Handle(XCAFDoc_KinematicTool) aTool = XCAFDoc_DocumentTool::KinematicTool(aDoc->Main());
   TDF_Label aJoint;
-  if (!getLabel(di, aDoc, argv[2], aJoint) || !aTool->IsJoint(aJoint))
+  if (!getLabel(di, aDoc, argv[2], aJoint))
     return 1;
 
   Handle(XCAFDoc_KinematicPair) aPair;
-  if (aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair)) {
-    Handle(XCAFKinematics_PairObject) anObject = aPair->GetObject();
-    Standard_Integer aTrsfNb = Draw::Atoi(argv[3]);
-    Standard_CString aName = argv[4];
-    switch (aTrsfNb) {
-    case 1: DrawTrSurf::Set(aName, new Geom_Plane(anObject->FirstTransformation()));
-      break;
-    case 2: DrawTrSurf::Set(aName, new Geom_Plane(anObject->SecondTransformation()));
-      break;
-    default:
-      di << "Invalid number of transformation\n";
-      return 1;
-    }
+  if (!aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair)) {
+    di << "Invalid kinematic pair object\n";
+    return 1;
+  }
+
+  Handle(XCAFKinematics_PairObject) anObject = aPair->GetObject();
+  Standard_Integer aTrsfNb = Draw::Atoi(argv[3]);
+  Standard_CString aName = argv[4];
+  switch (aTrsfNb) {
+  case 1: DrawTrSurf::Set(aName, new Geom_Plane(anObject->FirstTransformation()));
+    break;
+  case 2: DrawTrSurf::Set(aName, new Geom_Plane(anObject->SecondTransformation()));
+    break;
+  default:
+    di << "Invalid number of transformation\n";
+    return 1;
   }
 
   return 0;
@@ -817,21 +836,24 @@ static Standard_Integer setLimits(Draw_Interpretor& di, Standard_Integer argc, c
 
   Handle(XCAFDoc_KinematicTool) aTool = XCAFDoc_DocumentTool::KinematicTool(aDoc->Main());
   TDF_Label aJoint;
-  if (!getLabel(di, aDoc, argv[2], aJoint) || !aTool->IsJoint(aJoint))
+  if (!getLabel(di, aDoc, argv[2], aJoint))
     return 1;
 
+  Handle(XCAFDoc_KinematicPair) aPair;
+  if (!aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair)) {
+    di << "Invalid kinematic pair object\n";
+    return 1;
+  }
+
   Handle(TColStd_HArray1OfReal) aLimitArray = new TColStd_HArray1OfReal(1, argc - 3);
   for (Standard_Integer i = 3; i < argc; i++) {
     aLimitArray->ChangeValue(i - 2) = Draw::Atof(argv[i]);
   }
 
-  Handle(XCAFDoc_KinematicPair) aPair;
-  if (aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair)) {
-    Handle(XCAFKinematics_PairObject) anObject = aPair->GetObject();
-    anObject->SetAllLimits(aLimitArray);
-    if (anObject->HasLimits())
-      aPair->SetObject(anObject);
-  }
+  Handle(XCAFKinematics_PairObject) anObject = aPair->GetObject();
+  anObject->SetAllLimits(aLimitArray);
+  if (anObject->HasLimits())
+    aPair->SetObject(anObject);
 
   return 0;
 }
@@ -853,7 +875,7 @@ static Standard_Integer getLimits(Draw_Interpretor& di, Standard_Integer argc, c
 
   Handle(XCAFDoc_KinematicTool) aTool = XCAFDoc_DocumentTool::KinematicTool(aDoc->Main());
   TDF_Label aJoint;
-  if (!getLabel(di, aDoc, argv[2], aJoint) || !aTool->IsJoint(aJoint))
+  if (!getLabel(di, aDoc, argv[2], aJoint))
     return 1;
 
   Handle(XCAFDoc_KinematicPair) aPair;
@@ -888,30 +910,33 @@ static Standard_Integer setParameters(Draw_Interpretor& di, Standard_Integer arg
 
   Handle(XCAFDoc_KinematicTool) aTool = XCAFDoc_DocumentTool::KinematicTool(aDoc->Main());
   TDF_Label aJoint;
-  if (!getLabel(di, aDoc, argv[2], aJoint) || !aTool->IsJoint(aJoint))
+  if (!getLabel(di, aDoc, argv[2], aJoint))
+    return 1;
+
+  Handle(XCAFDoc_KinematicPair) aPair;
+  if (!aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair)) {
+    di << "Invalid kinematic pair object\n";
     return 1;
+  }
 
   Handle(TColStd_HArray1OfReal) aParamArray = new TColStd_HArray1OfReal(1, argc - 3);
   for (Standard_Integer i = 3; i < argc; i++) {
     aParamArray->ChangeValue(i - 2) = Draw::Atof(argv[i]);
   }
 
-  Handle(XCAFDoc_KinematicPair) aPair;
-  if (aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair)) {
-    Handle(XCAFKinematics_LowOrderPairObjectWithCoupling) anObject = 
-      Handle(XCAFKinematics_LowOrderPairObjectWithCoupling)::DownCast(aPair->GetObject());
-    if (!anObject.IsNull()) {
-      anObject->SetAllParams(aParamArray);
-      aPair->SetObject(anObject);
-      return 0;
-    }
-    Handle(XCAFKinematics_LowOrderPairObject) aLowObject =
-      Handle(XCAFKinematics_LowOrderPairObject)::DownCast(aPair->GetObject());
-    if (!aLowObject.IsNull()) {
-      aLowObject->SetSkewAngle(aParamArray->First());
-      aPair->SetObject(aLowObject);
-      return 0;
-    }
+  Handle(XCAFKinematics_LowOrderPairObjectWithCoupling) anObject =
+    Handle(XCAFKinematics_LowOrderPairObjectWithCoupling)::DownCast(aPair->GetObject());
+  if (!anObject.IsNull()) {
+    anObject->SetAllParams(aParamArray);
+    aPair->SetObject(anObject);
+    return 0;
+  }
+  Handle(XCAFKinematics_LowOrderPairObject) aLowObject =
+    Handle(XCAFKinematics_LowOrderPairObject)::DownCast(aPair->GetObject());
+  if (!aLowObject.IsNull()) {
+    aLowObject->SetSkewAngle(aParamArray->First());
+    aPair->SetObject(aLowObject);
+    return 0;
   }
 
   di << "Wrong type of object\n";
@@ -935,44 +960,45 @@ static Standard_Integer getParameters(Draw_Interpretor& di, Standard_Integer arg
 
   Handle(XCAFDoc_KinematicTool) aTool = XCAFDoc_DocumentTool::KinematicTool(aDoc->Main());
   TDF_Label aJoint;
-  if (!getLabel(di, aDoc, argv[2], aJoint) || !aTool->IsJoint(aJoint))
+  if (!getLabel(di, aDoc, argv[2], aJoint))
     return 1;
 
   Handle(XCAFDoc_KinematicPair) aPair;
-  if (aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair)) {
-    Handle(XCAFKinematics_LowOrderPairObjectWithCoupling) anObject =
-      Handle(XCAFKinematics_LowOrderPairObjectWithCoupling)::DownCast(aPair->GetObject());
-    if (anObject.IsNull()) {
-      Handle(XCAFKinematics_LowOrderPairObject) aLowObject =
-        Handle(XCAFKinematics_LowOrderPairObject)::DownCast(aPair->GetObject());
-      if (!aLowObject.IsNull() &&
-          (aLowObject->Type() == XCAFKinematics_PairType_Universal ||
-           aLowObject->Type() == XCAFKinematics_PairType_Homokinetic)) {
-        di << "Skew Angle = " << aLowObject->SkewAngle();
-        return 0;
-      }
-      else {
-        di << "Wrong type of object\n";
-        return 1;
-      }
+  if (!aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair))
+    return 1;
+
+  Handle(XCAFKinematics_LowOrderPairObjectWithCoupling) anObject =
+    Handle(XCAFKinematics_LowOrderPairObjectWithCoupling)::DownCast(aPair->GetObject());
+  if (anObject.IsNull()) {
+    Handle(XCAFKinematics_LowOrderPairObject) aLowObject =
+      Handle(XCAFKinematics_LowOrderPairObject)::DownCast(aPair->GetObject());
+    if (!aLowObject.IsNull() &&
+      (aLowObject->Type() == XCAFKinematics_PairType_Universal ||
+        aLowObject->Type() == XCAFKinematics_PairType_Homokinetic)) {
+      di << "Skew Angle = " << aLowObject->SkewAngle();
+      return 0;
     }
-    switch (anObject->Type()) {
-    case XCAFKinematics_PairType_Screw:
-      di << "Pitch = " << anObject->Pitch();
-      break;
-    case XCAFKinematics_PairType_RackAndPinion:
-    case XCAFKinematics_PairType_LinearFlexibleAndPinion:
-      di << "Pinion Radius = " << anObject->PinionRadius();
-      break;
-    case XCAFKinematics_PairType_Gear:
-      di << "First Link Radius = " << anObject->RadiusFirstLink() << "\n";
-      di << "Second Link Radius = " << anObject->RadiusSecondLink() << "\n";
-      di << "Bevel = " << anObject->Bevel() << "\n";
-      di << "Helical Angle = " << anObject->HelicalAngle() << "\n";
-      di << "Gear Ratio = " << anObject->GearRatio();
-      break;
+    else {
+      di << "Wrong type of object\n";
+      return 1;
     }
   }
+  switch (anObject->Type()) {
+  case XCAFKinematics_PairType_Screw:
+    di << "Pitch = " << anObject->Pitch();
+    break;
+  case XCAFKinematics_PairType_RackAndPinion:
+  case XCAFKinematics_PairType_LinearFlexibleAndPinion:
+    di << "Pinion Radius = " << anObject->PinionRadius();
+    break;
+  case XCAFKinematics_PairType_Gear:
+    di << "First Link Radius = " << anObject->RadiusFirstLink() << "\n";
+    di << "Second Link Radius = " << anObject->RadiusSecondLink() << "\n";
+    di << "Bevel = " << anObject->Bevel() << "\n";
+    di << "Helical Angle = " << anObject->HelicalAngle() << "\n";
+    di << "Gear Ratio = " << anObject->GearRatio();
+    break;
+  }
 
   return 0;
 }
@@ -994,21 +1020,22 @@ static Standard_Integer setOrientation(Draw_Interpretor& di, Standard_Integer ar
 
   Handle(XCAFDoc_KinematicTool) aTool = XCAFDoc_DocumentTool::KinematicTool(aDoc->Main());
   TDF_Label aJoint;
-  if (!getLabel(di, aDoc, argv[2], aJoint) || !aTool->IsJoint(aJoint))
+  if (!getLabel(di, aDoc, argv[2], aJoint))
     return 1;
 
   Handle(XCAFDoc_KinematicPair) aPair;
-  if (aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair)) {
-    Handle(XCAFKinematics_PairObject) anObject = aPair->GetObject();
-    Handle(XCAFKinematics_HighOrderPairObject) aHighObject =
-      Handle(XCAFKinematics_HighOrderPairObject)::DownCast(anObject);
-    if (aHighObject.IsNull()) {
-      di << "Error: Orientation could be applied only for high order kinematic pair\n";
-      return 1;
-    }
-    aHighObject->SetOrientation(Draw::Atoi(argv[3]) != 0 );
-    aPair->SetObject(anObject);
+  if (!aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair))
+    return 1;
+
+  Handle(XCAFKinematics_PairObject) anObject = aPair->GetObject();
+  Handle(XCAFKinematics_HighOrderPairObject) aHighObject =
+    Handle(XCAFKinematics_HighOrderPairObject)::DownCast(anObject);
+  if (aHighObject.IsNull()) {
+    di << "Error: Orientation could be applied only for high order kinematic pair\n";
+    return 1;
   }
+  aHighObject->SetOrientation(Draw::Atoi(argv[3]) != 0);
+  aPair->SetObject(anObject);
 
   return 0;
 }
@@ -1030,20 +1057,20 @@ static Standard_Integer getOrientation(Draw_Interpretor& di, Standard_Integer ar
 
   Handle(XCAFDoc_KinematicTool) aTool = XCAFDoc_DocumentTool::KinematicTool(aDoc->Main());
   TDF_Label aJoint;
-  if (!getLabel(di, aDoc, argv[2], aJoint) || !aTool->IsJoint(aJoint))
+  if (!getLabel(di, aDoc, argv[2], aJoint))
     return 1;
 
   Handle(XCAFDoc_KinematicPair) aPair;
-  if (aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair)) {
-    Handle(XCAFKinematics_PairObject) anObject = aPair->GetObject();
-    Handle(XCAFKinematics_HighOrderPairObject) aHighObject =
-      Handle(XCAFKinematics_HighOrderPairObject)::DownCast(anObject);
-    if (aHighObject.IsNull()) {
-      di << "Error: Orientation could be applied only for high order kinematic pair\n";
-      return 1;
-    }
-    di << aHighObject->Orientation();
+  if (!aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair))
+    return 1;
+  Handle(XCAFKinematics_PairObject) anObject = aPair->GetObject();
+  Handle(XCAFKinematics_HighOrderPairObject) aHighObject =
+    Handle(XCAFKinematics_HighOrderPairObject)::DownCast(anObject);
+  if (aHighObject.IsNull()) {
+    di << "Error: Orientation could be applied only for high order kinematic pair\n";
+    return 1;
   }
+  di << aHighObject->Orientation();
 
   return 0;
 }
@@ -1065,7 +1092,7 @@ static Standard_Integer setGeomParam(Draw_Interpretor& di, Standard_Integer argc
 
   Handle(XCAFDoc_KinematicTool) aTool = XCAFDoc_DocumentTool::KinematicTool(aDoc->Main());
   TDF_Label aJoint;
-  if (!getLabel(di, aDoc, argv[2], aJoint) || !aTool->IsJoint(aJoint))
+  if (!getLabel(di, aDoc, argv[2], aJoint))
     return 1;
   Handle(XCAFDoc_KinematicPair) aPair;
   if (!aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair)) {
@@ -1130,6 +1157,8 @@ static Standard_Integer setGeomParam(Draw_Interpretor& di, Standard_Integer argc
     }
     if (anObject->Type() == XCAFKinematics_PairType_PointOnPlanarCurve)
       anObject->SetCurve(aCurve);
+    else if (anObject->Type() == XCAFKinematics_PairType_LinearFlexibleAndPlanarCurve)
+      anObject->SetFirstCurve(aCurve);
     else {
       switch (aParamNb) {
       case 1: anObject->SetFirstCurve(aCurve);
@@ -1164,7 +1193,7 @@ static Standard_Integer getGeomParam(Draw_Interpretor& di, Standard_Integer argc
     return 1;
   Handle(XCAFDoc_KinematicTool) aTool = XCAFDoc_DocumentTool::KinematicTool(aDoc->Main());
   TDF_Label aJoint;
-  if (!getLabel(di, aDoc, argv[2], aJoint) || !aTool->IsJoint(aJoint))
+  if (!getLabel(di, aDoc, argv[2], aJoint))
     return 1;
   Handle(XCAFDoc_KinematicPair) aPair;
   if (!aJoint.FindAttribute(XCAFDoc_KinematicPair::GetID(), aPair)) {
@@ -1207,10 +1236,12 @@ static Standard_Integer getGeomParam(Draw_Interpretor& di, Standard_Integer argc
     // Curve
     Handle(Geom_Curve) aCurve;
     if (anObject->Type() == XCAFKinematics_PairType_PointOnPlanarCurve)
-    if (!anObject->HasLimits())
-      aCurve = anObject->Curve();
-    else
-      aCurve = anObject->TrimmedCurve();
+      if (!anObject->HasLimits())
+        aCurve = anObject->Curve();
+      else
+        aCurve = anObject->TrimmedCurve();
+    else if(anObject->Type() == XCAFKinematics_PairType_LinearFlexibleAndPlanarCurve)
+      aCurve = anObject->FirstCurve();
     else {
       switch (aTrsfNb) {
       case 1: aCurve = anObject->FirstCurve();
@@ -1268,15 +1299,12 @@ static Standard_Integer removeMechanismState(Draw_Interpretor& di, Standard_Inte
     return 1;
 
   TDF_Label aState;
-  if (!getLabel(di, aDoc, argv[2], aState) && aState.Father().Tag() != 3)
+  if (!getLabel(di, aDoc, argv[2], aState))
     return 1;  
   
   Handle(XCAFDoc_KinematicTool) aTool = XCAFDoc_DocumentTool::KinematicTool(aDoc->Main());
-  TDF_Label aMechanism = aState.Father().Father();
-  if(!aTool->IsMechanism(aMechanism))
-    return 1;
-
   aTool->RemoveState(aState);
+
   return 0;
 }
 
@@ -1296,12 +1324,10 @@ static Standard_Integer addValues(Draw_Interpretor& di, Standard_Integer argc, c
     return 1;
   Handle(XCAFDoc_KinematicTool) aTool = XCAFDoc_DocumentTool::KinematicTool(aDoc->Main());
   TDF_Label aState;
-  if (!getLabel(di, aDoc, argv[2], aState))
+  if (!getLabel(di, aDoc, argv[2], aState) || !aTool->IsState(aState))
     return 1;
-  TDF_Label aMechanism = aState.Father().Father();
+  TDF_Label aValue = aTool->AddValue(aState);
 
-  TDF_TagSource aTag;
-  TDF_Label aValue = aTag.NewChild(aState);
   if (argc == 3)
   {
     Handle(XCAFDoc_KinematicPairValue) aPairValue;
@@ -1309,7 +1335,7 @@ static Standard_Integer addValues(Draw_Interpretor& di, Standard_Integer argc, c
   }
   else {
     TDF_Label aJoint;
-    if (!getLabel(di, aDoc, argv[3], aJoint) || !aTool->IsJoint(aJoint))
+    if (!getLabel(di, aDoc, argv[3], aJoint))
       return 1;
 
     Handle(XCAFKinematics_PairValueObject) anObject;
@@ -1401,9 +1427,8 @@ static Standard_Integer setValues(Draw_Interpretor& di, Standard_Integer argc, c
     return 1;
   Handle(XCAFDoc_KinematicTool) aTool = XCAFDoc_DocumentTool::KinematicTool(aDoc->Main());
   TDF_Label aJoint;
-  if (!getLabel(di, aDoc, argv[3], aJoint) || !aTool->IsJoint(aJoint))
+  if (!getLabel(di, aDoc, argv[3], aJoint))
     return 1;
-  TDF_Label aMechanism = aJoint.Father().Father();
   TDF_Label aValue;
   if (!getLabel(di, aDoc, argv[2], aValue) || !aTool->IsValue(aValue))
     return 1;
@@ -1418,19 +1443,15 @@ static Standard_Integer setValues(Draw_Interpretor& di, Standard_Integer argc, c
   }
   Handle(XCAFKinematics_PairObject) aPairObject = aPair->GetObject();
 
-  if (aValue.FindAttribute(XCAFDoc_KinematicPairValue::GetID(), aPairValue))
-  {
-    aPairValue = XCAFDoc_KinematicPairValue::Set(aValue, aJoint);
-    anObject = aPairValue->GetObject();
-    if (anObject->GetAllValues().IsNull())
-      anObject->SetType(aPairObject->Type());
+  if (!aValue.FindAttribute(XCAFDoc_KinematicPairValue::GetID(), aPairValue)) {
+    di << "Invalid kinematic value object\n";
+    return 1;
   }
-  else {
-    anObject = new XCAFKinematics_PairValueObject();
-    aPairValue = XCAFDoc_KinematicPairValue::Set(aValue,aJoint);
+  anObject = aPairValue->GetObject();
+  if (anObject->GetAllValues().IsNull() ||
+      anObject->Type() != aPairObject->Type())
     anObject->SetType(aPairObject->Type());
-  }
-
+  XCAFDoc_KinematicPairValue::Set(aValue, aJoint);
   try {
     Standard_Integer anIt = 4;
     while (anIt < argc) {
@@ -1506,10 +1527,9 @@ static Standard_Integer getValues(Draw_Interpretor& di, Standard_Integer argc, c
     return 1;
   Handle(XCAFDoc_KinematicTool) aTool = XCAFDoc_DocumentTool::KinematicTool(aDoc->Main());
   TDF_Label aValue;
-  if (!getLabel(di, aDoc, argv[2], aValue) || !aTool->IsValue(aValue))
+  if (!getLabel(di, aDoc, argv[2], aValue))
     return 1;
 
-
   Handle(XCAFKinematics_PairValueObject) anObject;
   Handle(XCAFDoc_KinematicPairValue) aPairValue;
   if (aValue.FindAttribute(XCAFDoc_KinematicPairValue::GetID(), aPairValue))
@@ -1584,7 +1604,7 @@ static Standard_Integer removeValues(Draw_Interpretor& di, Standard_Integer argc
     return 1;
   Handle(XCAFDoc_KinematicTool) aTool = XCAFDoc_DocumentTool::KinematicTool(aDoc->Main());
   TDF_Label aValue;
-  if (!getLabel(di, aDoc, argv[2], aValue) && !aTool->IsValue(aValue))
+  if (!getLabel(di, aDoc, argv[2], aValue))
     return 1;
 
   aTool->RemoveValue(aValue);
@@ -1625,18 +1645,18 @@ static Standard_Integer dump(Draw_Interpretor& di, Standard_Integer argc, const
     nbLowOrderPairWithMotionCouplingValues = 0,
     nbLowOrderPairValues = 0;
 
-  for (Standard_Integer aMechInd = 1; aMechInd <= aMechanisms.Length(); ++aMechInd) 
+  for (TDF_LabelSequence::Iterator anIt(aMechanisms); anIt.More(); anIt.Next())
   {
-    TDF_Label aMechanism = aMechanisms.Value(aMechInd);
+    TDF_Label aMechanism = anIt.Value();
     TDF_LabelSequence aLinks = aKTool->GetLinks(aMechanism);
     nbLinks += aLinks.Length();
     for (Standard_Integer aLinkInd = 1; aLinkInd <= nbLinks; ++aLinkInd)
       nbRefShapes += aKTool->GetRefShapes(aLinks.Value(aLinkInd)).Length();
     TDF_LabelSequence aJoints = aKTool->GetJoints(aMechanism);
-    for (Standard_Integer aJointInd = 1; aJointInd <= aJoints.Length(); ++aJointInd)
+    for (TDF_LabelSequence::Iterator anIt(aJoints); anIt.More(); anIt.Next())
     {
       Handle(XCAFDoc_KinematicPair) aKinAttr;
-      if (!aJoints.Value(aJointInd).FindAttribute(XCAFDoc_KinematicPair::GetID(), aKinAttr))
+      if (!anIt.Value().FindAttribute(XCAFDoc_KinematicPair::GetID(), aKinAttr))
         continue;
       Handle(XCAFKinematics_PairObject) anObject = aKinAttr->GetObject();
       if (anObject.IsNull())
@@ -1649,7 +1669,7 @@ static Standard_Integer dump(Draw_Interpretor& di, Standard_Integer argc, const
           nbLowOrderPairsWithRange++;
         else
           nbLowOrderPairs++;
-        nbLowOrderPairValues += aKTool->GetValuesOfJoint(aJoints.Value(aJointInd)).Length();
+        nbLowOrderPairValues += aKTool->GetValuesOfJoint(anIt.Value()).Length();
       }
       else if (aKinType >= XCAFKinematics_PairType_Screw &&
                aKinType <= XCAFKinematics_PairType_LinearFlexibleAndPinion)
@@ -1658,7 +1678,7 @@ static Standard_Integer dump(Draw_Interpretor& di, Standard_Integer argc, const
           nbLowOrderPairsWithMotionCouplingAndRange++;
         else
           nbLowOrderPairsWithMotionCoupling++;
-        nbLowOrderPairWithMotionCouplingValues += aKTool->GetValuesOfJoint(aJoints.Value(aJointInd)).Length();
+        nbLowOrderPairWithMotionCouplingValues += aKTool->GetValuesOfJoint(anIt.Value()).Length();
       }
       else if (aKinType >= XCAFKinematics_PairType_PointOnSurface &&
                aKinType <= XCAFKinematics_PairType_LinearFlexibleAndPlanarCurve)
@@ -1667,7 +1687,7 @@ static Standard_Integer dump(Draw_Interpretor& di, Standard_Integer argc, const
           nbHigeOrderPairsWithRange++;
         else
           nbHigeOrderPairs++;
-        nbHigeOrderPairValues += aKTool->GetValuesOfJoint(aJoints.Value(aJointInd)).Length();
+        nbHigeOrderPairValues += aKTool->GetValuesOfJoint(anIt.Value()).Length();
       }
     }
     nbStates += aKTool->GetStates(aMechanism).Length();
@@ -1822,6 +1842,7 @@ void XDEDRAW_Kinematics::InitCommands(Draw_Interpretor& di)
     "\tScrew - Pitch\n"
     "\tRackAndPinion - PinionRadius\n"
     "\tGear -FirstLinkRadius SecondLinkRadius Bevel HelicalAngle GearRatio \n"
+    "\tLinear - SkewAngle \n"
     __FILE__, setParameters, g);
 
   di.Add("XGetPairParams", "XGetPairParams Doc Joint",
index a9db18cf0f98d1abf05e5518e29c1d251ff935ae..8d45cdb63c9a524455ebe7e878ca57da345dee81 100644 (file)
@@ -2,9 +2,8 @@
 # Test scenario for kinematics
 #==============================
 
- ReadStep D [locate_data_file as1-oc-214.stp]
 # Load document with shape structure
-# ReadStep D C:/Work/files/as1.stp
+ReadStep D [locate_data_file as1-oc-214.stp]
 # Add parent mechanism
 set mech [XAddMechanism D]
 
diff --git a/tests/gdt/kinematics_export/A1 b/tests/gdt/kinematics_export/A1
deleted file mode 100644 (file)
index 7bbf95c..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-# !!!! This file is generated automatically, do not edit manually! See end script
-set filename chuck_3_jaw_AP242_v2.stp
-
-set ref_data {
-
- NbOfMechanisms             : ( 1 )
- NbOfKinematicLinks         : ( 4 )
- NbOfRefShapes              : ( 4 )
- KinematicPairsWithoutRange :  NbOfLowOrderPairs ( 0 ) NbOfLowOrderPairsWithMotionCoupling ( 0 ) NbOfHightOrderPairs ( 0 )
- KinematicPairsWithRange    :  NbOfLowOrderPairs ( 3 ) NbOfLowOrderPairsWithMotionCoupling ( 0 ) NbOfHightOrderPairs ( 0 )
- NbOfStates                 : ( 2 )
- KinematicValues            :  NbOfLowOrderPairs ( 6 ) NbOfLowOrderPairsWithMotionCoupling ( 0 ) NbOfHightOrderPairs ( 0 )
-}
diff --git a/tests/gdt/kinematics_export/A2 b/tests/gdt/kinematics_export/A2
deleted file mode 100644 (file)
index 7a3daec..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-# !!!! This file is generated automatically, do not edit manually! See end script
-set filename mazak_kinematic_v3.stp
-
-set ref_data {
-
- NbOfMechanisms             : ( 1 )
- NbOfKinematicLinks         : ( 8 )
- NbOfRefShapes              : ( 8 )
- KinematicPairsWithoutRange :  NbOfLowOrderPairs ( 2 ) NbOfLowOrderPairsWithMotionCoupling ( 0 ) NbOfHightOrderPairs ( 0 )
- KinematicPairsWithRange    :  NbOfLowOrderPairs ( 5 ) NbOfLowOrderPairsWithMotionCoupling ( 0 ) NbOfHightOrderPairs ( 0 )
- NbOfStates                 : ( 10 )
- KinematicValues            :  NbOfLowOrderPairs ( 15 ) NbOfLowOrderPairsWithMotionCoupling ( 0 ) NbOfHightOrderPairs ( 0 )
-}
diff --git a/tests/gdt/kinematics_export/bug31388_1 b/tests/gdt/kinematics_export/bug31388_1
new file mode 100644 (file)
index 0000000..538c342
--- /dev/null
@@ -0,0 +1,13 @@
+# !!!! This file is generated automatically, do not edit manually! See end script
+set filename bug31388_1.stp
+
+set ref_data {
+
+ NbOfMechanisms             : ( 1 )
+ NbOfKinematicLinks         : ( 4 )
+ NbOfRefShapes              : ( 4 )
+ KinematicPairsWithoutRange :  NbOfLowOrderPairs ( 0 ) NbOfLowOrderPairsWithMotionCoupling ( 0 ) NbOfHightOrderPairs ( 0 )
+ KinematicPairsWithRange    :  NbOfLowOrderPairs ( 3 ) NbOfLowOrderPairsWithMotionCoupling ( 0 ) NbOfHightOrderPairs ( 0 )
+ NbOfStates                 : ( 2 )
+ KinematicValues            :  NbOfLowOrderPairs ( 6 ) NbOfLowOrderPairsWithMotionCoupling ( 0 ) NbOfHightOrderPairs ( 0 )
+}
diff --git a/tests/gdt/kinematics_export/bug31388_2 b/tests/gdt/kinematics_export/bug31388_2
new file mode 100644 (file)
index 0000000..3e8b4a4
--- /dev/null
@@ -0,0 +1,13 @@
+# !!!! This file is generated automatically, do not edit manually! See end script
+set filename bug31388_2.stp
+
+set ref_data {
+
+ NbOfMechanisms             : ( 1 )
+ NbOfKinematicLinks         : ( 8 )
+ NbOfRefShapes              : ( 8 )
+ KinematicPairsWithoutRange :  NbOfLowOrderPairs ( 2 ) NbOfLowOrderPairsWithMotionCoupling ( 0 ) NbOfHightOrderPairs ( 0 )
+ KinematicPairsWithRange    :  NbOfLowOrderPairs ( 5 ) NbOfLowOrderPairsWithMotionCoupling ( 0 ) NbOfHightOrderPairs ( 0 )
+ NbOfStates                 : ( 10 )
+ KinematicValues            :  NbOfLowOrderPairs ( 15 ) NbOfLowOrderPairsWithMotionCoupling ( 0 ) NbOfHightOrderPairs ( 0 )
+}
index 6d8d5dca7c846a27434e40b7d6c11d4ff921a95e..31101d3ab23840f9126deb27c9a56f50f60e0063 100644 (file)
@@ -99,7 +99,7 @@ if { $mist < 1} {
   if { [llength $xst2] > 0 } {
     regexp {NbOfMechanisms +: +[(] +([-0-9.+eE]+) +[)]} $xst2 full nbMechanism_Second
     regexp {NbOfKinematicLinks +: +[(] +([-0-9.+eE]+) +[)]} $xst2 full nbLink_Second
-    regexp {NbOfRefShapes +: +[(] +([-0-9.+eE]+) +[)]} $xst2 full nbRefShape_Secondt
+    regexp {NbOfRefShapes +: +[(] +([-0-9.+eE]+) +[)]} $xst2 full nbRefShape_Second
     regexp {KinematicPairsWithoutRange +: +NbOfLowOrderPairs +[(] +([-0-9.+eE]+) +[)] +NbOfLowOrderPairsWithMotionCoupling +[(] +([-0-9.+eE]+) +[)] +NbOfHightOrderPairs +[(] +([-0-9.+eE]+) +[)]} $xst2 full nbLowPair_Second nbLowPairWthMotCoupl_Second nbHighPair_Second 
     regexp {KinematicPairsWithRange +: +NbOfLowOrderPairs +[(] +([-0-9.+eE]+) +[)] +NbOfLowOrderPairsWithMotionCoupling +[(] +([-0-9.+eE]+) +[)] +NbOfHightOrderPairs +[(] +([-0-9.+eE]+) +[)]} $xst2 full nbLowPairWthRng_Second nbLowPairWthMotCouplAndRng_Second nbHighPairWthRng__Second
     regexp {NbOfStates +: +[(] +([-0-9.+eE]+) +[)]} $xst2 full nbState_Second