if(BFlag != (DR16_RemotePoint()->Wheel >= 500.0)){ BFlag = (DR16_RemotePoint()->Wheel >= 500.0); if(BFlag){ Number_tag += 1; } } if(LFlag != (DR16_RemotePoint()->Wheel <= -500.0 )){ LFlag = (DR16_RemotePoint()->Wheel <= -500.0); if(LFlag){ Number_tag -= 1; } } while(Number_tag > 4){ Number_tag -= 4; } while(Number_tag < 1){ Number_tag += 4; }
时间: 2024-04-20 08:24:48 浏览: 12
这段代码是一个条件判断和循环的代码块。首先,它比较DR16_RemotePoint()->Wheel的值是否大于等于500.0,并将结果与BFlag进行比较。如果两者不相等,BFlag将被更新为DR16_RemotePoint()->Wheel >= 500.0的结果。如果BFlag为true,则Number_tag增加1。
接下来,它比较DR16_RemotePoint()->Wheel的值是否小于等于-500.0,并将结果与LFlag进行比较。如果两者不相等,LFlag将被更新为DR16_RemotePoint()->Wheel <= -500.0的结果。如果LFlag为true,则Number_tag减去1。
然后,它使用while循环,将Number_tag的值限制在1到4之间。如果Number_tag大于4,则通过减去4来将其限制在1到4之间。如果Number_tag小于1,则通过加上4来将其限制在1到4之间。
总而言之,这段代码的作用是根据DR16_RemotePoint()->Wheel的值来更新BFlag、LFlag和Number_tag,并确保Number_tag的值在1到4之间。
相关问题
@GetMapping("/details") public ResponseInfo<String> Details(@RequestParam String id){ List<eventCamerVo> eventVos = null; boolean bFlag = false; eventCamerVo eventCameraVO = JSONObject.parseObject(id, eventCamerVo.class); Event event = eventService.getById(eventCameraVO.getId()); if (1 == event.getEvent_type()){ eventVos = eventMapper.getAll(id); } if (3 == event.getEvent_type()){ eventVos = slopeWarMapper.getAllSlope(id); } return ResponseInfo.success(eventVos.toString()); }从这段代码可以看出前端传来一个id,我拿到id去查event表,如果查到这条数据的type==1就调用这个方法,List<eventCamerVo> getAll(@Param("id") String id); 如果拿到的type==3就调用这个方法List<eventCamerVo> getAllSlope(@Param("id") String id);,请根据需求指出代码的错误并修改
从代码中看不出具体的错误,但是需要对代码进行优化和修改,如下所示:
1. 对于前端传来的id参数,需要进行非空判断,如果为null或者空字符串,需要返回相应的错误提示。
2. 对于从数据库中查询到的Event对象,需要进行非空判断,如果为null,需要返回相应的错误提示。
3. 对于event.getEvent_type()的返回值,需要进行非空判断,如果为null,需要返回相应的错误提示。
4. 根据需求,如果拿到的type不等于1或者3,需要返回相应的错误提示。
5. 对于getAll和getAllSlope方法的调用,需要进行非空判断,如果返回null或者空列表,需要返回相应的错误提示。
修改后的代码如下所示:
@GetMapping("/details")
public ResponseInfo<String> Details(@RequestParam String id) {
if (id == null || id.isEmpty()) {
return ResponseInfo.fail("参数id不能为空");
}
eventCamerVo eventCameraVO = JSONObject.parseObject(id, eventCamerVo.class);
Event event = eventService.getById(eventCameraVO.getId());
if (event == null) {
return ResponseInfo.fail("查询不到对应的事件信息");
}
Integer eventType = event.getEvent_type();
if (eventType == null) {
return ResponseInfo.fail("查询到的事件类型为空");
}
List<eventCamerVo> eventVos;
if (eventType == 1) {
eventVos = eventMapper.getAll(id);
} else if (eventType == 3) {
eventVos = slopeWarMapper.getAllSlope(id);
} else {
return ResponseInfo.fail("不支持的事件类型");
}
if (eventVos == null || eventVos.isEmpty()) {
return ResponseInfo.fail("未查询到相关数据");
}
return ResponseInfo.success(eventVos.toString());
}
objectarx二次开发自定义实体,实体数据是一个结构体tagGmyMapTable,结构体tagGmyMapTable中包含另外一个结构体tagGeometryWithID、一个类指针ElmGraphic*、一个bool变量,而结构体tagGeometryWithID保存的是一个unsigned long long int数据和一个vector<wstring>.类指针ElmGraphic*中有一个vector<shared_ptr<CBaseGeometry>> ptrgeos, CBaseGeometry是个基类,使用时会根据CBaseGeometry中的int型type的参数判断强制转换成不同子类进行绘制,子类中的数据也不相同,CBaseGeometry中包含了vector<AcGePoint3D>以及字符串、int等数据,请问如何保存读取这些数据到dwg
首先,需要定义一个继承自 AcDbEntity 的实体类 GmyMapTableEntity,然后在 GmyMapTableEntity 类中定义一个成员变量,类型为 tagGmyMapTable 结构体,用于保存实体数据。
在实现 GmyMapTableEntity 类的 dwg 文件读写方法时,可以将 tagGmyMapTable 结构体的成员变量依次读写到 dwg 文件中。
具体实现方法如下:
1. 在 GmyMapTableEntity.h 文件中定义 GmyMapTableEntity 类,并在类定义中添加 tagGmyMapTable 结构体成员变量。
```C++
class GmyMapTableEntity : public AcDbEntity
{
public:
GmyMapTableEntity();
virtual ~GmyMapTableEntity();
// dwg 文件读写方法
virtual Acad::ErrorStatus dwgInFields(AcDbDwgFiler* filer) override;
virtual Acad::ErrorStatus dwgOutFields(AcDbDwgFiler* filer) const override;
private:
tagGmyMapTable m_gmyMapTableData; // 实体数据
};
```
2. 在 GmyMapTableEntity.cpp 文件中实现 dwg 文件读写方法。具体实现过程如下:
- dwgInFields 方法
```C++
Acad::ErrorStatus GmyMapTableEntity::dwgInFields(AcDbDwgFiler* filer)
{
assertReadEnabled();
Acad::ErrorStatus es = AcDbEntity::dwgInFields(filer);
if (es != Acad::eOk) return es;
// 读取 tagGmyMapTable 结构体中的数据
es = filer->readItem(&m_gmyMapTableData.geometryData);
if (es != Acad::eOk) return es;
// 读取 ElmGraphic* 中的数据
if (filer->filerStatus() == Acad::eOk && m_gmyMapTableData.pElmGraphic != nullptr)
{
// 读取 vector<shared_ptr<CBaseGeometry>> 中的数据
Adesk::UInt32 count = 0;
filer->readUInt32(&count);
for (Adesk::UInt32 i = 0; i < count; i++)
{
// 读取 CBaseGeometry::type
int type = 0;
filer->readInt32(&type);
// 根据 CBaseGeometry::type 创建对应的子类对象
std::shared_ptr<CBaseGeometry> pGeometry;
if (type == CLine::Type)
{
pGeometry = std::make_shared<CLine>();
}
else if (type == CCircle::Type)
{
pGeometry = std::make_shared<CCircle>();
}
else if (type == CArc::Type)
{
pGeometry = std::make_shared<CArc>();
}
else
{
pGeometry = std::make_shared<CBaseGeometry>();
}
// 读取子类对象的数据
if (filer->filerStatus() == Acad::eOk)
{
pGeometry->dwgInFields(filer);
}
// 将子类对象添加到 vector<shared_ptr<CBaseGeometry>> 中
m_gmyMapTableData.pElmGraphic->ptrgeos.push_back(pGeometry);
}
// 读取 bool 变量
filer->readBool(&m_gmyMapTableData.bFlag);
}
return filer->filerStatus();
}
```
- dwgOutFields 方法
```C++
Acad::ErrorStatus GmyMapTableEntity::dwgOutFields(AcDbDwgFiler* filer) const
{
assertReadEnabled();
Acad::ErrorStatus es = AcDbEntity::dwgOutFields(filer);
if (es != Acad::eOk) return es;
// 写入 tagGmyMapTable 结构体中的数据
es = filer->writeItem(m_gmyMapTableData.geometryData);
if (es != Acad::eOk) return es;
// 写入 ElmGraphic* 中的数据
if (filer->filerStatus() == Acad::eOk && m_gmyMapTableData.pElmGraphic != nullptr)
{
// 写入 vector<shared_ptr<CBaseGeometry>> 中的数据
Adesk::UInt32 count = static_cast<Adesk::UInt32>(m_gmyMapTableData.pElmGraphic->ptrgeos.size());
filer->writeUInt32(count);
for (const auto& pGeometry : m_gmyMapTableData.pElmGraphic->ptrgeos)
{
// 写入 CBaseGeometry::type
int type = pGeometry->type();
filer->writeInt32(type);
// 写入子类对象的数据
if (filer->filerStatus() == Acad::eOk)
{
pGeometry->dwgOutFields(filer);
}
}
// 写入 bool 变量
filer->writeBool(m_gmyMapTableData.bFlag);
}
return filer->filerStatus();
}
```
3. 在主程序中,使用 AcDbBlockTableRecord::newEntity 方法创建 GmyMapTableEntity 实体对象,并将实体数据保存到 tagGmyMapTable 结构体成员变量中。
```C++
void createGmyMapTableEntity()
{
// 创建 GmyMapTableEntity 实体对象
GmyMapTableEntity* pGmyMapTableEntity = new GmyMapTableEntity;
// 设置实体数据
pGmyMapTableEntity->m_gmyMapTableData.geometryData.id = 1234567890;
pGmyMapTableEntity->m_gmyMapTableData.geometryData.name = L"MyMapTable";
pGmyMapTableEntity->m_gmyMapTableData.pElmGraphic = new ElmGraphic;
pGmyMapTableEntity->m_gmyMapTableData.bFlag = true;
// 设置 CLine 对象的数据
std::shared_ptr<CLine> pLine = std::make_shared<CLine>();
pLine->setStartPoint(AcGePoint3d(0, 0, 0));
pLine->setEndPoint(AcGePoint3d(10, 0, 0));
pGmyMapTableEntity->m_gmyMapTableData.pElmGraphic->ptrgeos.push_back(pLine);
// 设置 CCircle 对象的数据
std::shared_ptr<CCircle> pCircle = std::make_shared<CCircle>();
pCircle->setCenter(AcGePoint3d(5, 5, 0));
pCircle->setRadius(5);
pGmyMapTableEntity->m_gmyMapTableData.pElmGraphic->ptrgeos.push_back(pCircle);
// 添加实体对象到块表记录中
AcDbBlockTableRecord* pBlockTableRecord = getCurrentSpaceBlockTableRecord();
pBlockTableRecord->appendAcDbEntity(pGmyMapTableEntity);
pGmyMapTableEntity->close();
}
```
上述代码中的 getCurrentSpaceBlockTableRecord 方法用于获取当前空间的块表记录对象。
这样,就可以实现自定义实体的保存和读取了。
相关推荐
![ppt](https://img-home.csdnimg.cn/images/20210720083527.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)