美文网首页
CATIA-V5-工程图中“假数据”的处理

CATIA-V5-工程图中“假数据”的处理

作者: 游在路上的鱼 | 来源:发表于2019-02-27 20:58 被阅读0次

    在创建工程图中,常常需要进行某些位置的尺寸标注。通常只需要将需要投影的点投影至工程图中,两点之间的标注数值也就是两个点的实际距离。但有些时候的标注值不是两个点的距离值,此时需要对此“假数据”进行标注。
    // ------------------------------------------------
    /**

    • @brief 直接根据两点创建距离标注

    • @param[in] ipSectionView 工程图view

    • @param[in] iPosition 工程图第一点

    • @param[in] iPosition2 工程图第二点

    • @param[in] iChangeValFlg 是否需要变更距离标注值

    • @param[in] idValue 假标注值

    • @param[in] dimRep 引线类型

    • @retval TRUE:创建成功 FALSE:创建失败

    • @note [详细说明]

    • @attention [注意事项说明]
      /
      // ------------------------------------------------
      CATBoolean CreateDimFrom2DPntPos(
      CATIView
      ipSectionView,
      double* iPosition,
      double* iPosition2,
      CATMathPoint2D iMovePos,
      const int& iChangeValFlg,
      const double& idValue,
      CATDrwDimRepresentation dimRep)
      {
      cout<<"dimension"<<endl;
      CATVisPropertiesValues piTextPropertiesPoint;
      piTextPropertiesPoint.SetSymbol(CROSS);
      CATIVisProperties * pvispropties=NULL;
      CATVisPropertyType iPropertyType = CATVPSymbol;

      CATIDrwAnnotationFactory_var spAnnFactory=NULL_var;
      ipSectionView->QueryInterface(IID_CATIDrwAnnotationFactory,(void **)&spAnnFactory);

      CATI2DWFFactory_var sp2DFactory;
      ipSectionView->QueryInterface(IID_CATI2DWFFactory,(void **)&sp2DFactory);

      if (sp2DFactory == NULL_var)
      {
      cout << "Can not get Factory!" <<endl;
      return FALSE;
      }
      CATISpecObject_var sp2DPoint1 = sp2DFactory->CreatePoint(iPosition);
      if (sp2DPoint1 == NULL_var)
      {
      cout << "Can not create point!" <<endl;
      return FALSE;
      }
      sp2DPoint1->Update();
      if(SUCCEEDED(sp2DPoint1->QueryInterface(IID_CATIVisProperties,(void **)&pvispropties)))
      {
      //cout<<" >>>>>>>success"<<endl;
      pvispropties->SetPropertiesAtt(piTextPropertiesPoint,iPropertyType,CATVPPoint);
      pvispropties->Release();
      pvispropties = NULL;
      }

      CATISpecObject_var sp2DPoint2 = sp2DFactory->CreatePoint(iPosition2);
      sp2DPoint2->Update();
      if(SUCCEEDED(sp2DPoint2->QueryInterface(IID_CATIVisProperties,(void **)&pvispropties)))
      {
      //cout<<" >>>>>>>success"<<endl;
      pvispropties->SetPropertiesAtt(piTextPropertiesPoint,iPropertyType,CATVPPoint);
      pvispropties->Release();
      pvispropties = NULL;
      }

      CATDrwDimType dimType = DrwDimDistance;
      CATMathPoint2D iMathAnchorPt1(iPosition);
      CATMathPoint2D iMathAnchorPt2(iPosition2);
      CATIDrwDimDimension* piDim = NULL;
      CATDimDefinition dimDef;
      dimDef.Orientation = dimRep;
      dimDef.OrientationReference=ParallelScreen;
      HRESULT rc = CreateAnnoDimension(sp2DPoint1,sp2DPoint2,dimType,dimDef,iMovePos,ipSectionView,piDim);
      if (!SUCCEEDED(rc))
      {
      cout<< "Create Dim Failed"<<endl;
      return FALSE;
      }

      //更改字体大小
      CATIDrwTextProperties pDimensionTextProperties = NULL;
      piDim->QueryInterface(IID_CATIDrwTextProperties,(void
      *)&pDimensionTextProperties);
      if (pDimensionTextProperties == NULL)
      {
      cout<<"failed in getting CATIDrwTextProperties!"<<endl;
      return FALSE ;
      }
      pDimensionTextProperties->SetFontName("FangSong_GB2312 (TrueType)");
      pDimensionTextProperties->SetFontSize(2.5);

      if (piDim != NULL && iChangeValFlg == 1)
      {
      // 标注假尺寸
      CATIDrwDimValue_var spDrwDimValue = piDim->GetValue();
      if (spDrwDimValue != NULL_var)
      {
      CATIDrwDimFakeComponent_var spiFakeValue = spDrwDimValue->GetFakeComponent();
      if (NULL_var != spiFakeValue)
      {
      CATUnicodeString ustrFakeVal;
      ustrFakeVal.BuildFromNum(idValue);
      spiFakeValue->SetFakeMode(CATDrwDimFakeNumValue);
      spiFakeValue->SetMainFakeValue(ustrFakeVal);
      }
      }
      }

      //更新
      CATISpecObject_var sptmp = piDim;
      sptmp->Update();
      return TRUE;
      }

    // ------------------------------------------------
    /** CreateAnnoDimension

    • @brief [Create Dimension]

    • @param[in] ipiFirAssistFeat 第一个特征

    • @param[in] ipiSecAssistFeat 第二个特征

    • @param[in] idrwDimType Dimension Type

    • @param[in] idimDefinition Dimension Defintion

    • @param[in] imAnnoLoc 标注位置

    • @param[in] ipiView 标注视图

    • @param[out] ipiDim 输出的Dimension

    • @retval HRESULT:
      S_OK 成功
      Other 失败

    • @note

    • @attention [注意事项说明]
      /
      // -----------------------------------------------
      HRESULT CreateAnnoDimension(
      CATISpecObject_var& ipiFirAssistFeat,
      CATISpecObject_var& ipiSecAssistFeat,
      CATDrwDimType idrwDimType,
      CATDimDefinition idimDefinition,
      CATMathPoint2D& imAnnoLoc,
      CATIView
      ipiView,
      CATIDrwDimDimension*& opiDim)
      {
      HRESULT rc = S_OK;

      // 1、获取标注工厂
      CATIDrwAnnotationFactory_var spiDrwAnnotationFactory = ipiView;
      if (spiDrwAnnotationFactory == NULL)
      {
      return E_OUTOFMEMORY;
      }
      // 2、设置要素列表
      CATIUnknownList* piSelectionList = NULL;
      CATIUnknownListImpl* piListImpl = new CATIUnknownListImpl();
      rc = piListImpl->QueryInterface(IID_CATIUnknownList, (void)&piSelectionList);
      if (piSelectionList == NULL)
      {
      return E_OUTOFMEMORY;
      }
      IUnknown
      piUnknownOnFirst = NULL;
      ipiFirAssistFeat->QueryInterface(IID_IUnknown, (void
      )&piUnknownOnFirst);
      if (piUnknownOnFirst == NULL)
      {
      return E_OUTOFMEMORY;
      }
      IUnknown
      piUnknownOnSecond = NULL;
      ipiSecAssistFeat->QueryInterface(IID_IUnknown, (void**)&piUnknownOnSecond);
      if (piUnknownOnSecond == NULL)
      {
      return E_OUTOFMEMORY;
      }
      piSelectionList->Add(0, piUnknownOnFirst);
      piSelectionList->Add(1, piUnknownOnSecond);
      // 3、计算标注位置
      double dPnt[2] = {10.0, 15.0};
      double *pts[2];
      pts[0] = dPnt;
      pts[1] = dPnt + 1;
      // 4、标注角度
      rc = spiDrwAnnotationFactory->CreateDimension(piSelectionList,
      pts,idrwDimType,&idimDefinition,&opiDim);
      if (opiDim == NULL)
      {
      return E_INVALIDARG;
      }

      // 设置尺寸精度
      CATIDrwDimValue_var spiDrwDimValue = opiDim->GetValue();
      if (spiDrwDimValue != NULL_var)
      {
      CATIDrwDimValueComponent_var spiMainValue = spiDrwDimValue->GetFaceComponent();
      if (NULL_var != spiMainValue)
      {
      CATIDrwDimFormat_var spiDimFormat = spiMainValue->GetFormat();
      if (NULL_var != spiDimFormat)
      {
      spiDimFormat->SetFormatPrecision(0.001);
      }
      }
      }

      // 延长尺寸线
      CATIDrwDimExtensionLine_var spiDimExtLine = opiDim->GetExtensionLine();
      if (spiDimExtLine != NULL_var)
      {
      spiDimExtLine->SetGap(0.0);
      }

      opiDim->MoveValue(imAnnoLoc);

      if (piUnknownOnFirst != NULL)
      {
      piUnknownOnFirst->Release();
      piUnknownOnFirst = NULL;
      }
      if (piUnknownOnSecond != NULL)
      {
      piUnknownOnSecond->Release();
      piUnknownOnSecond = NULL;
      }

      if (piSelectionList != NULL)
      {
      piSelectionList->Release();
      piSelectionList = NULL;
      }

      if (piListImpl != NULL)
      {
      delete piListImpl;
      }

      return rc;
      }

    相关文章

      网友评论

          本文标题:CATIA-V5-工程图中“假数据”的处理

          本文链接:https://www.haomeiwen.com/subject/dudquqtx.html