android 开发第一部分 kotlin Jetpack compose 开发JOG界面

ContinueAndStepSwitchInterface





package com.hxrobot.ui.teach.PointTeach

import RobotGrpc.Robot
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.*
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.*
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewmodel.compose.viewModel
import com.hxrobot.data.GrpcConnectionManager
import com.hxrobot.ui.teach.ertherdassdsfsfsf.PlainButton2
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch


@Composable
fun SetRobotStepSizeInterface2() {
    val viewModel: SetRobotStepSizeViewModel2 = viewModel()
    var valueIndex by remember { mutableStateOf(4) }//对应发送0.1的步长->默认连续运动
    Box(modifier = Modifier.size(230.dp,230.dp)){
        //val size =(200f/density).dp
        val size = 230.dp
        val centerXY  = size*0.5f
        val multiple = size/100f.dp
        Box(
            modifier = Modifier
                .fillMaxSize()
                //.zIndex(2f)
                .clip(SectorShape3(6, 4))
                .background(Color.Unspecified)
                .clickable {
                    valueIndex = 4
                    viewModel.button0()
                }
        ) {
            Text(
                modifier = Modifier
                    .graphicsLayer {
                        translationX = translationX.plus((centerXY-(18*multiple).dp).toPx())
                        translationY = translationY.plus(0f.dp.toPx())
                    },text = "连续运动", color = (if(valueIndex == 4) Color(0xFF3153CE) else Color(0xFF1C253D )), fontSize = 18.sp,)
        }
        Box(
            modifier = Modifier
                .fillMaxSize()
                //.zIndex(2f)
                .clip(SectorShape3(6, 5))
                .background(Color.Unspecified)
                .clickable {
                    valueIndex = 5
                    viewModel.button1()
                }
        ) {
            Text(
                modifier = Modifier
                    .graphicsLayer {
                        translationX = translationX.plus((centerXY+(37*multiple).dp).toPx())
                        translationY = translationY.plus((centerXY-(30*multiple).dp).toPx())
                    },text = "1", color = (if(valueIndex == 5) Color(0xFF3153CE) else Color(0xFF1C253D )), fontSize = 20.sp,)
        }
        Box(
            modifier = Modifier
                .fillMaxSize()
                //.zIndex(2f)
                .clip(SectorShape3(6, 0))
                .background(Color.Unspecified)
                .clickable {
                    valueIndex = 0
                    viewModel.button2()
                }
        ) {
            Text(
                modifier = Modifier
                    .graphicsLayer {
                        translationX = translationX.plus((centerXY+(32*multiple).dp).toPx())
                        translationY = translationY.plus((centerXY+(17*multiple).dp).toPx())
                    },text = "0.1", color = (if(valueIndex == 0) Color(0xFF3153CE) else Color(0xFF1C253D )), fontSize = 20.sp,)
        }
        Box(
            modifier = Modifier
                .fillMaxSize()
                //.zIndex(2f)
                .clip(SectorShape3(6, 1))
                .background(Color.Unspecified)
                .clickable {
                    valueIndex = 1
                    viewModel.button3()
                }
        ) {
            Text(
                modifier = Modifier
                    .graphicsLayer {
                        translationX = translationX.plus((centerXY-(8*multiple).dp).toPx())
                        translationY = translationY.plus((centerXY+(40*multiple).dp).toPx())
                    },text = "0.01", color = (if(valueIndex == 1) Color(0xFF3153CE) else Color(0xFF1C253D )), fontSize = 20.sp,)
        }
        //0.84  0.8
        //132/150 /126
        Box(modifier = Modifier.absoluteOffset(centerXY-((0.79f*size.value)/2f).dp,centerXY-((0.79f*size.value)/2f).dp)){
            InnerCircleLineOutSideExtrude(sizeX = (0.79f)*size.value, sizeY = (0.79f)*size.value)
        }
        //128/150 /
        Box(modifier = Modifier.absoluteOffset(centerXY-((0.76f*size.value)/2f).dp,centerXY-((0.76f*size.value)/2f).dp)){
            InnerCircleLineOutSide(sizeX = (0.76f)*size.value, sizeY = (0.76f)*size.value)
        }
        //90/150
        Box(modifier = Modifier.size((0.6f)*size).absoluteOffset(centerXY-((0.6f*size.value)/2f).dp,centerXY-((0.6f*size.value)/2f).dp)){
            InnerCircleInRotaryMax3()
        }
        //75/150
        Box(modifier = Modifier.size((0.5f)*size).absoluteOffset(centerXY-((0.5f*size.value)/2f).dp,centerXY-((0.5f*size.value)/2f).dp)){
            InnerCircleInRotaryMax4()
        }
        Box(modifier = Modifier.absoluteOffset(centerXY-((0.5f*size.value)/2f).dp,centerXY-((0.5f*size.value)/2f).dp)){
            InnerCircleRotaryInside(sizeX = (0.5f)*size.value, sizeY = (0.5f)*size.value, startAngle = (valueIndex +1) * 60f-30f-4f )
        }
    }
}
class SectorShape3(val parts: Int,val currentPart:Int) : Shape {
    override fun createOutline(
        size: Size,
        layoutDirection: LayoutDirection,
        density: Density, ): Outline {
        val rect = Rect(0f, 0f, size.width, size.height)
        val angelOfEachSection = 360f/parts
        //定义画笔的路径
        val path = Path().apply {
            // 将坐标系原点移动到画布中央
            moveTo(size.width / 2f, size.height / 2f)//移动到起点
            addArc(rect, (currentPart)*angelOfEachSection, angelOfEachSection)
            lineTo(size.width / 2f, size.height / 2f)//移动到终点
//            //moveTo(size.width / 2f, size.height / 2f)//移动到起点
//            arcTo(rect,0f,90f,true)
//            arcTo(rect,270f,360f,true)
        }
        //返回路径的轮廓
        return Outline.Generic(path)
    }
}
@Composable
fun InnerCircleLineOutSide(
    canvasSize: Dp = 128.dp,
    indicatorValue: Int = 0,
    maxIndicatorValue: Int = 100,
    backgroundIndicatorColor: Color =Color(0xFFF1F4F4),
    backgroundIndicatorStrokeWidth: Float = 100f,
    foregroundIndicatorColor: Color = Color(0xFFFD0D2D5),
    foregroundIndicatorStrokeWidth: Float = 5f,
    startAngle: Float = 270f,
    sizeX: Float = 128f,
    sizeY: Float = 128f
){
    Box(
        modifier = Modifier
            .size(sizeX.dp, sizeY.dp)
            .drawBehind {
                val componentSize = size
                foregroundIndicator2(
                    componentSize = componentSize,
                    indicatorColor = foregroundIndicatorColor,
                    indicatorStrokeWidth = foregroundIndicatorStrokeWidth,
                    startAngle = startAngle
                )
            }
    ) {
    }
}
fun DrawScope.foregroundIndicator2(
    componentSize: Size,
    indicatorColor: Color,
    indicatorStrokeWidth: Float,
    startAngle :Float
) {
    drawArc(
        size = componentSize,
        color = indicatorColor,
        startAngle = startAngle,
        sweepAngle = 180f,
        useCenter = false,
        style = Stroke(
            width = indicatorStrokeWidth,
            cap = StrokeCap.Butt
        ),
        topLeft = Offset(
            x = (size.width - componentSize.width) / 2f,
            y = (size.height - componentSize.height) / 2f
        )
    )
}
@Composable
fun InnerCircleLineOutSideExtrude(
    foregroundIndicatorColor: Color = Color(0xFFFD0D2D5),
    foregroundIndicatorStrokeWidth: Float = 10f,
    startAngle: Float = 270f,
    sweepAngle :Float = 300f,
    sizeX: Float = 132f,
    sizeY: Float = 132f
){
    Box(
        modifier = Modifier
            .size(sizeX.dp, sizeY.dp)
            .drawBehind {
                val componentSize = size
                generalIndicator(
                    componentSize = componentSize,
                    Color = foregroundIndicatorColor,
                    StrokeWidth = foregroundIndicatorStrokeWidth,
                    startAngle = 269f,
                    sweepAngle = 2f
                )
                generalIndicator(
                    componentSize = componentSize,
                    Color = foregroundIndicatorColor,
                    StrokeWidth = foregroundIndicatorStrokeWidth,
                    startAngle = 329f,
                    sweepAngle = 2f
                )
                generalIndicator(
                    componentSize = componentSize,
                    Color = foregroundIndicatorColor,
                    StrokeWidth = foregroundIndicatorStrokeWidth,
                    startAngle = 29f,
                    sweepAngle = 2f
                )
                generalIndicator(
                    componentSize = componentSize,
                    Color = foregroundIndicatorColor,
                    StrokeWidth = foregroundIndicatorStrokeWidth,
                    startAngle = 89f,
                    sweepAngle = 2f
                )
            }
    ) {
    }
}
fun DrawScope.generalIndicator(
    componentSize: Size,
    Color: Color,
    StrokeWidth: Float,
    startAngle :Float,
    sweepAngle :Float
) {
    drawArc(
        size = componentSize,
        color = Color,
        startAngle = startAngle,
        sweepAngle = sweepAngle,
        useCenter = false,
        style = Stroke(
            width = StrokeWidth,
            cap = StrokeCap.Butt
        ),
        topLeft = Offset(
            x = (size.width - componentSize.width) / 2f,
            y = (size.height - componentSize.height) / 2f
        )
    )
}
@Composable
fun InnerCircleInRotaryMax3() {
    Box(modifier = Modifier
        .fillMaxSize()
        .background(
            shape = CircleShape,
            brush = Brush.verticalGradient(listOf(Color.White, Color.White))
        )
            //listOf(Color(0xFFF1F4F4), Color(0xFFF1F4F4))
        .border(
            width = 2.dp,
            brush = Brush.verticalGradient(listOf(Color.Gray.copy(0.15f), Color.Gray.copy(0.08f))),
            shape = CircleShape,
        )
//        .drawBehind {
//            drawArc(
//                color = Color(0xFFF1F4F4),
//                startAngle = 0f,
//                sweepAngle = 360f,
//                useCenter = true,
//            )
//        }
    )
}
@Composable
fun InnerCircleInRotaryMax4() {
    Box(modifier = Modifier
        .fillMaxSize()
        .background(
            shape = CircleShape,
            brush = Brush.verticalGradient(listOf(Color(0xFFECF3F9), Color(0xFFECF3F9)))
        )
    )
}
@Composable
fun InnerCircleRotaryInside(
    foregroundIndicatorColor: Color = Color(0xFF2A4CC8),
    foregroundIndicatorStrokeWidth: Float = 27f,
    startAngle: Float = 270f,
    sizeX: Float = 98f,
    sizeY: Float = 98f
){
    Box(
        modifier = Modifier
            .size(sizeX.dp, sizeY.dp)
            .background(Color.Unspecified)
            .drawBehind {
                val componentSize = size
                foregroundIndicator3(
                    componentSize = componentSize,
                    indicatorColor = foregroundIndicatorColor,
                    indicatorStrokeWidth = foregroundIndicatorStrokeWidth,
                    startAngle = startAngle
                )
            }
    ) {
    }
}
fun DrawScope.foregroundIndicator3(
    componentSize: Size,
    indicatorColor: Color,
    indicatorStrokeWidth: Float,
    startAngle :Float
) {
    drawArc(
        size = componentSize,
        color = indicatorColor,
        startAngle = startAngle,
        sweepAngle = 8f,
        useCenter = false,
        style = Stroke(
            width = indicatorStrokeWidth,
            cap = StrokeCap.Butt
        ),
        topLeft = Offset(
            x = (size.width - componentSize.width) / 2f,
            y = (size.height - componentSize.height) / 2f
        )
    )
}

CurrentPointPositionInterface.kt

package com.hxrobot.ui.teach.PointTeach

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.hxrobot.ui.teach.CurrentPointInformationViewModel2
import com.hxrobot.ui.teach.InformationFromPointList3
import com.hxrobot.ui.teach.PositionModeChangeViewModel2
import com.hxrobot.ui.teach.SetRobotCoordinateModeViewModel2
import com.hxrobot.ui.teach.ertherdassdsfsfsf.FontStyle3

/***************************************************************************当前选中点位的信息界面*****/
@Composable
fun CurrentPointPositionShowInterface2(){
    val interfaceChangeViewModel: SetRobotCoordinateModeViewModel2 = viewModel()
    //val interfaceChangeViewModel: PositionModeChangeViewModel2 = viewModel()//切换不同显示模式
    val viewModelForPoint: CurrentPointInformationViewModel2 = viewModel()//当前点位信息操作
    val nameChangeViewModel: InformationFromPointList3 = viewModel()//从上方获取到当前的点位名称

    val curName by nameChangeViewModel.curNameLiveData.observeAsState("nullName")
    viewModelForPoint.showPointData(curName)


    //实际上此处应该把实际处理完的所有值作为观察对象,应该观察用于显示在界面上的数据
    //监控获取到的数据,若为空,重新获取并刷新界面
    val getGrpcValue by viewModelForPoint.robotPointValueListLiveData.observeAsState(null)
//    val getGrpcValueOfPoint = try {
//        viewModelForPoint.robotPointValueListLiveData
//    } catch (e: Exception) {
//        // 处理异常,例如记录日志或显示错误消息
//        null
//    }
    if(getGrpcValue == null){
        viewModelForPoint.showPointData(curName)
    }
    //显示点位
    when (interfaceChangeViewModel.coordinateModeValue) {
        2,3 -> {
            val stringlistCartes: Array<String> = arrayOf("X  ", "Y   ", "Z   ", "Rz ", "Flip ", "Rz")
            Column(
                modifier = Modifier
                    .fillMaxSize()
                    .background(Color.Unspecified)
//                    .background(
//                        Brush.verticalGradient(
//                        listOf(Color(0xFF4263BC), Color(0xFF5678E7) )
//                    ))
            ) {
                Row( modifier = Modifier
                    .weight(0.6f)
                    .padding(top = 10f.dp, start = 10.dp, end = 10.dp, bottom = 0.dp)) {
                    Text(text = "当前点位位置-位姿值", style = FontStyle3,
                        modifier = Modifier.fillMaxWidth())
                }
                Row( modifier = Modifier
                    .weight(3f)
                    .padding(top = 0f.dp, start = 10.dp, end = 10.dp, bottom = 10.dp)) {
                    Column(
                        modifier = Modifier
                            .weight(3.2f)
                            .padding(all = 10.dp)
                    ) {
                        Text(text = "${stringlistCartes.getOrNull(0)?.padEnd(10)}${String.format("%1.3f",
                            viewModelForPoint.posListOfCartes.getOrNull(0)
                        ).padEnd(15)}", style = FontStyle3)
                        Text(text = "${stringlistCartes.getOrNull(1)?.padEnd(10)}${String.format("%1.3f",
                            viewModelForPoint.posListOfCartes.getOrNull(1)
                        ).padEnd(15)}", style = FontStyle3)
                        Text(text = "${stringlistCartes.getOrNull(2)?.padEnd(10)}${String.format("%1.3f",
                            viewModelForPoint.posListOfCartes.getOrNull(2)
                        ).padEnd(15)}", style = FontStyle3)
                        Text(text = "${stringlistCartes.getOrNull(3)?.padEnd(10)}${String.format("%1.3f",
                            viewModelForPoint.posListOfCartes.getOrNull(3)
                        ).padEnd(15)}", style = FontStyle3)
                        Text(text = "${stringlistCartes.getOrNull(4)?.padEnd(10)}${String.format("%1.3f",
                            viewModelForPoint.posListOfExtJoint.getOrNull(0)
                        ).padEnd(15)}", style = FontStyle3)
                    }
                    Column(
                        modifier = Modifier
                            .weight(2.5f)
                            .padding(all = 10.dp)
                    ) {
                        Text(text = "mm",style = FontStyle3)
                        Text(text = "mm",style = FontStyle3)
                        Text(text = "mm",style = FontStyle3)
                        Text(text = "°",style = FontStyle3)
                        Text(text = "°",style = FontStyle3)
                    }
                }




//                Column(
//                    modifier = Modifier
//                        .fillMaxSize()
//                        .padding(all = 10.dp)
//                ) {
//                    Text(text = "当前点位位置-位姿值", style = FontStyle3,
//                        modifier = Modifier
//                            .fillMaxWidth())
//                    Text(text = "${stringlistCartes.getOrNull(0)}     ${String.format("%1.3f",
//                        viewModelForPoint.posListOfCartes.getOrNull(0)
//                    )}    mm", style = FontStyle3)
//                    Text(text = "${stringlistCartes.getOrNull(1)}    ${String.format("%1.3f",
//                        viewModelForPoint.posListOfCartes.getOrNull(1)
//                    )}    mm", style = FontStyle3)
//                    Text(text = "${stringlistCartes.getOrNull(2)}    ${String.format("%1.3f",
//                        viewModelForPoint.posListOfCartes.getOrNull(2)
//                    )}    mm", style = FontStyle3)
//                    Text(text = "${stringlistCartes.getOrNull(3)}    ${String.format("%1.3f",
//                        viewModelForPoint.posListOfCartes.getOrNull(3)
//                    )}    °", style = FontStyle3)
//                    Text(text = "${stringlistCartes.getOrNull(4)}  ${String.format("%1.3f",
//                        viewModelForPoint.posListOfExtJoint.getOrNull(0)
//                    )}    °", style = FontStyle3)
//                }
            }
        }
        1 -> {
            val stringlistJoint: Array<String> = arrayOf(" Z ", "J2 ", "J3 ", "J4 ", "Flip ", "J6 ")
            Column(
                modifier = Modifier
                    .fillMaxSize()
                    .background(Color.Unspecified)
//                    .background(Brush.verticalGradient(
//                        listOf(Color(0xFF4263BC), Color(0xFF5678E7) )
//                    ))
            ) {
                Row( modifier = Modifier
                    .weight(0.6f)
                    .padding(top = 10f.dp, start = 10.dp, end = 10.dp, bottom = 0.dp)) {
                    Text(text = "当前点位位置-关节值", style = FontStyle3,
                        modifier = Modifier.fillMaxWidth())
                }
                Row( modifier = Modifier
                    .weight(3f)
                    .padding(top = 0f.dp, start = 10.dp, end = 10.dp, bottom = 10.dp)) {
                    Column(
                        modifier = Modifier
                            .weight(3.2f)
                            .padding(all = 10.dp)
                    ) {
                        Text(text = "${stringlistJoint.getOrNull(0)?.padEnd(10)}${String.format("%1.3f",
                            viewModelForPoint.posListOfJoints.getOrNull(0)
                        ).padEnd(15)}", style = FontStyle3)
                        Text(text = "${stringlistJoint.getOrNull(1)?.padEnd(10)}${String.format("%1.3f",
                            viewModelForPoint.posListOfJoints.getOrNull(1)
                        ).padEnd(15)}", style = FontStyle3)
                        Text(text = "${stringlistJoint.getOrNull(2)?.padEnd(10)}${String.format("%1.3f",
                            viewModelForPoint.posListOfJoints.getOrNull(2)
                        ).padEnd(15)}", style = FontStyle3)
                        Text(text = "${stringlistJoint.getOrNull(3)?.padEnd(10)}${String.format("%1.3f",
                            viewModelForPoint.posListOfJoints.getOrNull(3)
                        ).padEnd(15)}", style = FontStyle3)
                        Text(text = "${stringlistJoint.getOrNull(4)?.padEnd(10)}${String.format("%1.3f",
                            viewModelForPoint.posListOfExtJoint.getOrNull(0)
                        ).padEnd(15)}", style = FontStyle3)
                    }
                    Column(
                        modifier = Modifier
                            .weight(2.5f)
                            .padding(all = 10.dp)
                    ) {
                        Text(text = "mm",style = FontStyle3)
                        Text(text = "°",style = FontStyle3)
                        Text(text = "°",style = FontStyle3)
                        Text(text = "°",style = FontStyle3)
                        Text(text = "°",style = FontStyle3)
                    }
                }






//                Column(
//                    modifier = Modifier
//                        .fillMaxSize()
//                        .padding(all = 10.dp)
//                ) {
//                    Text(text = "当前点位位置-关节值", style = FontStyle3,
//                        modifier = Modifier
//                            .fillMaxWidth())
//                    Text(text = "${stringlistJoint.getOrNull(0)}     ${String.format("%1.3f",
//                        viewModelForPoint.posListOfJoints.getOrNull(0)
//                    )}    mm", style = FontStyle3)
//                    Text(text = "${stringlistJoint.getOrNull(1)}    ${String.format("%1.3f",
//                        viewModelForPoint.posListOfJoints.getOrNull(1)
//                    )}    °", style = FontStyle3)
//                    Text(text = "${stringlistJoint.getOrNull(2)}    ${String.format("%1.3f",
//                        viewModelForPoint.posListOfJoints.getOrNull(2)
//                    )}    °", style = FontStyle3)
//                    Text(text = "${stringlistJoint.getOrNull(3)}    ${String.format("%1.3f",
//                        viewModelForPoint.posListOfJoints.getOrNull(3)
//                    )}    °", style = FontStyle3)
//                    Text(text = "${stringlistJoint.getOrNull(4)}  ${String.format("%1.3f",
//                        viewModelForPoint.posListOfExtJoint.getOrNull(0)
//                    )}    °", style = FontStyle3)
//                }
            }
        }
        0 -> {
            val stringlistCylind: Array<String> = arrayOf("R ", "T ", "Z ","   ","Flip ","   ")
            Column(
                modifier = Modifier
                    .fillMaxSize()
                    .background(Color.Unspecified)
//                    .background(Brush.verticalGradient(
//                        listOf(Color(0xFF4263BC), Color(0xFF5678E7) )
//                    ))
            ) {
                Row( modifier = Modifier
                    .weight(0.6f)
                    .padding(top = 10f.dp, start = 10.dp, end = 10.dp, bottom = 0.dp)) {
                    Text(text = "当前点位位置-圆柱值", style = FontStyle3,
                        modifier = Modifier.fillMaxWidth())
                }
                Row( modifier = Modifier
                    .weight(3f)
                    .padding(top = 0f.dp, start = 10.dp, end = 10.dp, bottom = 10.dp)) {
                    Column(
                        modifier = Modifier
                            .weight(3.2f)
                            .padding(all = 10.dp)
                    ) {
                        Text(text = "${stringlistCylind.getOrNull(0)?.padEnd(10)}${String.format("%1.3f",
                            viewModelForPoint.posListOfCylind.getOrNull(0)
                        ).padEnd(15)}", style = FontStyle3)
                        Text(text = "${stringlistCylind.getOrNull(1)?.padEnd(10)}${String.format("%1.3f",
                            viewModelForPoint.posListOfCylind.getOrNull(1)
                        ).padEnd(15)}", style = FontStyle3)
                        Text(text = "${stringlistCylind.getOrNull(2)?.padEnd(10)}${String.format("%1.3f",
                            viewModelForPoint.posListOfCylind.getOrNull(2)
                        ).padEnd(15)}", style = FontStyle3)
                        Text(text = "${stringlistCylind.getOrNull(4)?.padEnd(10)}${String.format("%1.3f",
                            viewModelForPoint.posListOfExtJoint.getOrNull(0)
                        ).padEnd(15)}", style = FontStyle3)
                    }
                    Column(
                        modifier = Modifier
                            .weight(2.5f)
                            .padding(all = 10.dp)
                    ) {
                        Text(text = "°",style = FontStyle3)
                        Text(text = "°",style = FontStyle3)
                        Text(text = "°",style = FontStyle3)
                        Text(text = "°",style = FontStyle3)
                    }
                }




//                Column(
//                    modifier = Modifier
//                        .fillMaxSize()
//                        .padding(all = 10.dp)
//                ) {
//                    Text(text = "当前点位位置-圆柱值", style = FontStyle3,
//                        modifier = Modifier
//                            .fillMaxWidth())
//                    Text(text = "${stringlistCylind.getOrNull(0)}     ${String.format("%1.3f",
//                        viewModelForPoint.posListOfCylind.getOrNull(0)
//                    )}    °", style = FontStyle3)
//                    Text(text = "${stringlistCylind.getOrNull(1)}    ${String.format("%1.3f",
//                        viewModelForPoint.posListOfCylind.getOrNull(1)
//                    )}    °", style = FontStyle3)
//                    Text(text = "${stringlistCylind.getOrNull(2)}    ${String.format("%1.3f",
//                        viewModelForPoint.posListOfCylind.getOrNull(2)
//                    )}    °", style = FontStyle3)
//                    Text(text = "${stringlistCylind.getOrNull(4)}  ${String.format("%1.3f",
//                        viewModelForPoint.posListOfExtJoint.getOrNull(0)
//                    )}    °", style = FontStyle3)
//                }
            }
        }
    }


//
//    Column(modifier = Modifier
//        .width(500.dp)
//        .height(300.dp)) {
//        Text(text = "当前点位位置    (${interfaceChangeViewModel.changeText()})", fontSize = 24.sp,
//            modifier = Modifier
//                .fillMaxWidth()
//                .background(color = Color.Gray))
//        if(interfaceChangeViewModel.positionModeValue == 1){
//            PointPositionShowCompose(viewModelForPoint.stringlistExtJoint,
//                viewModelForPoint.posListOfExtJoint,
//                viewModelForPoint.stringlistCylind,
//                viewModelForPoint.posListOfCylind,
//                3)
//        }
//        else if(interfaceChangeViewModel.positionModeValue == 2){
//            PointPositionShowCompose(viewModelForPoint.stringlistExtJoint,
//                viewModelForPoint.posListOfExtJoint,
//                viewModelForPoint.stringlistJoint,
//                viewModelForPoint.posListOfJoints,
//                6)
//        }else{
//            PointPositionShowCompose(viewModelForPoint.stringlistExtJoint,
//                viewModelForPoint.posListOfExtJoint,
//                viewModelForPoint.stringlistCartes,
//                viewModelForPoint.posListOfCartes,
//                6)
//        }
//    }
}


/********************点位信息的子界面组件************/
@Composable
fun  PointPositionShowCompose(extjName :Array<String>,
                              extjValue: MutableList<Double>,
                              elementName:Array<String>,
                              elementValue: MutableList<Double>,
                              elementCount: Int){
    Column() {
        repeat(2) {
            Row(
            ) {
                Text(
                    text = "${extjName.getOrNull(it)}    ${
                        String.format(
                            "%1.3f",
                            extjValue.getOrNull(it)
                        )
                    }",
                    fontSize = 24.sp
                )
            }
        }
        repeat(elementCount) {
            Row(
            ) {
                Text(
                    text = "${elementName.getOrNull(it)}    ${
                        String.format(
                            "%1.3f",
                            elementValue.getOrNull(it)
                        )
                    }",
                    fontSize = 24.sp
                )
            }
        }
    }
}

JogButtonInterface.kt

package com.hxrobot.ui.teach.PointTeach

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.absoluteOffset
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.*
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.hxrobot.ui.teach.JogMoveGrpc
import com.hxrobot.ui.teach.ertherdassdsfsfsf.colorPaint2
@Composable
fun JogButtonLeftInterface(
){
    val viewModel: SetRobotStepSizeViewModel2 = viewModel()
    if(viewModel.valueChange != 0){
        JogButtonLeftInching()
    }else{
        JogButtonLeftContinue()
    }
}
@Composable
fun JogButtonRightInterface(){
    val viewModel: SetRobotStepSizeViewModel2 = viewModel()
    if(viewModel.valueChange != 0){
        JogButtonRightInching()
    }else{
        JogButtonRightContinue()
    }
}

@Composable
fun JogButtonLeftInching(){
    val joveMoveClass: JogMoveGrpc2 = JogMoveGrpc2()
    val curAxisViewModel: JogCurSwitchAxis = viewModel()//默认值 0
    val lastClickTime = remember { mutableStateOf(0L) }//用于计时,防止重复界面

    Button(onClick = {
        val currentTime = System.currentTimeMillis()//2000
        if (currentTime - lastClickTime.value > 800) {
            lastClickTime.value = currentTime
            joveMoveClass.jogMoveMessageforSend(curAxisViewModel.currentAxis, 0, false, true)
        }
    },
        colors = ButtonDefaults.buttonColors(
            backgroundColor = (Color(0xFFF1F4F4)),
        ),
        modifier = Modifier
            .size(70.dp)
            .clip(JogButtonLeftAndRightShape())
            .clickable { }
            .background(Color.Unspecified),
        elevation = ButtonDefaults.elevation(0.dp, 20.dp, 0.dp, 0.dp, 0.dp),
    ) {
        Box(modifier = Modifier
            .size(28.dp)
            .absoluteOffset(0.dp,0.dp)
            .clip(JogButtonLeftAndRightShape1())
            .background(Color(0xFF1563FF)),
        ) {
        }
    }
}
@Composable
fun JogButtonRightInching(){
    val joveMoveClass: JogMoveGrpc2 = JogMoveGrpc2()
    val curAxisViewModel: JogCurSwitchAxis = viewModel()//默认值 0
    val lastClickTime = remember { mutableStateOf(0L) }//用于计时,防止重复界面
    Button(onClick = {
        val currentTime = System.currentTimeMillis()
        if (currentTime - lastClickTime.value > 800) {
            lastClickTime.value = currentTime
            joveMoveClass.jogMoveMessageforSend(curAxisViewModel.currentAxis, 0, true, true)
        }
    },
        colors = ButtonDefaults.buttonColors(
            backgroundColor = (Color(0xFFF1F4F4)),
        ),
        elevation = ButtonDefaults.elevation(0.dp, 20.dp, 0.dp, 0.dp, 0.dp),
        modifier = Modifier
            .size(70.dp)
            .clip(JogButtonLeftAndRightShape())
            .clickable { }
            .background(Color.Unspecified)
    ) {
        Box(modifier = Modifier
            .size(28.dp)
            .absoluteOffset(0.dp,0.dp)
            .clip(JogButtonLeftAndRightShape2())
            .background(Color(0xFF1563FF)),
        ) {
        }
    }
}
@Composable
fun JogButtonLeftContinue(){
    val joveMoveClass: JogMoveGrpc2 = JogMoveGrpc2()
    val curAxisViewModel: JogCurSwitchAxis = viewModel()//默认值 0
    val interactionSource = remember { MutableInteractionSource() }
    val isPressed by interactionSource.collectIsPressedAsState()
    val lastClickTime = remember { mutableStateOf(0L) }//用于计时,防止重复界面
    if (isPressed){
        //Pressed
        val currentTime = System.currentTimeMillis()//2500
        if(currentTime - lastClickTime.value > 1500){
            println("按下了连续运动按钮")
            joveMoveClass.jogMoveMessageforSend(curAxisViewModel.currentAxis,1,false,true)
            DisposableEffect(Unit) {
                onDispose {
                    //released
                    lastClickTime.value = currentTime
                    joveMoveClass.jogMoveMessageforSend(curAxisViewModel.currentAxis,1,false,false)
                }
            }
        }
    }

    Button(onClick = {
    },
        interactionSource = interactionSource,
        colors = ButtonDefaults.buttonColors(
            backgroundColor = (Color(0xFFF1F4F4)),
        ),
        elevation = ButtonDefaults.elevation(0.dp, 20.dp, 0.dp, 0.dp, 0.dp),
        modifier = Modifier
            .size(70.dp)
            .clip(JogButtonLeftAndRightShape())
            .clickable { }
            .background(Color.Unspecified)
    ) {
        Box(modifier = Modifier
            .size(28.dp)
            .absoluteOffset(0.dp,0.dp)
            .clip(JogButtonLeftAndRightShape1())
            .background(Color(0xFF1563FF)),
        ) {
        }
    }
}
@Composable
fun JogButtonRightContinue(){
    val joveMoveClass: JogMoveGrpc2 = JogMoveGrpc2()
    val curAxisViewModel: JogCurSwitchAxis = viewModel()//默认值 0
    val interactionSource = remember { MutableInteractionSource() }
    val isPressed by interactionSource.collectIsPressedAsState()
    val lastClickTime = remember { mutableStateOf(0L) }//用于计时,防止重复界面
    if (isPressed){
        //Pressed
        val currentTime = System.currentTimeMillis()
        if(currentTime - lastClickTime.value > 1500){
            println("按下了连续运动按钮")
            joveMoveClass.jogMoveMessageforSend(curAxisViewModel.currentAxis,1,true,true)
            DisposableEffect(Unit) {
                onDispose {
                    //released
                    lastClickTime.value = currentTime
                    joveMoveClass.jogMoveMessageforSend(curAxisViewModel.currentAxis,1,true,false)
                }
            }
        }
    }

    Button(onClick = {
    },
        interactionSource = interactionSource,
        colors = ButtonDefaults.buttonColors(
            backgroundColor = (Color(0xFFF1F4F4)),
        ),
        elevation = ButtonDefaults.elevation(0.dp, 20.dp, 0.dp, 0.dp, 0.dp),
        modifier = Modifier
            .size(70.dp)
            .clip(JogButtonLeftAndRightShape())
            .clickable { }
            .background(Color.Unspecified)
    ) {
        Box(modifier = Modifier
            .size(28.dp)
            .absoluteOffset(0.dp,0.dp)
            .clip(JogButtonLeftAndRightShape2())
            .background(Color(0xFF1563FF)),
        ) {
        }
    }
}
class JogButtonLeftAndRightShape() : Shape {
    override fun createOutline(
        size: Size,
        layoutDirection: LayoutDirection,
        density: Density, ): Outline {
        val rect = Rect(0f, 0f, size.width, size.height)
        //定义画笔的路径
        val path = Path().apply {
            // 将坐标系原点移动到画布中央
            moveTo(size.width / 2f, size.height / 2f)//移动到起点
            addArc(rect, 0f,360f)
            lineTo(size.width / 2f, size.height / 2f)//移动到终点
        }
        //返回路径的轮廓
        return Outline.Generic(path)
    }
}
class JogButtonLeftAndRightShape1() : Shape {
    override fun createOutline(
        size: Size,
        layoutDirection: LayoutDirection,
        density: Density, ): Outline {
        val rect = Rect(0f, 0f, size.width, size.height)
        //定义画笔的路径
        val move = 1.9f
        val path = Path().apply {
            // 将坐标系原点移动到画布中央
            moveTo(0f, (size.height / 2f)-move)//移动到起点
            lineTo(size.width , (size.height / 2f)-move)
            lineTo(size.width, (size.height / 2f)+move)
            lineTo(0f, (size.height / 2f)+move)
            close()

        }
        //返回路径的轮廓
        return Outline.Generic(path)
    }
}
class JogButtonLeftAndRightShape2() : Shape {
    override fun createOutline(
        size: Size,
        layoutDirection: LayoutDirection,
        density: Density, ): Outline {
        val rect = Rect(0f, 0f, size.width, size.height)
        //定义画笔的路径
        val move = 1.9f
        val path = Path().apply {
            // 将坐标系原点移动到画布中央
            moveTo(0f, size.height / 2f-move)//移动到起点
            lineTo(size.width , size.height / 2f-move)
            lineTo(size.width, size.height / 2f+move)
            lineTo(0f, size.height / 2f+move)
            lineTo(0f, size.height / 2f-move)
            //close()
            moveTo(size.width/2f-move, 0f)//移动到起点
            lineTo(size.width/2f-move , size.height)
            lineTo(size.width/2f+move, size.height)
            lineTo(size.width/2f+move, 0f)
            lineTo(size.width/2f-move, 0f)
           // close()
        }
        //返回路径的轮廓
        return Outline.Generic(path)
    }
}

JogButtonMoveHandle.kt

package com.hxrobot.ui.teach.PointTeach

import RobotGrpc.Robot
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import com.hxrobot.data.GrpcConnectionManager
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

//函数-用于发送jogMove信息
class JogMoveGrpc2(){
    fun jogMoveMessageforSend(
        setAxis: Int,
        setMode: Int,
        setPosDir: Boolean,
        setPushdown: Boolean,
    ){
        CoroutineScope(Dispatchers.IO).launch {
            val sendMessage = Robot.JogMove.newBuilder()
                .setAxis(setAxis)
                .setMode(setMode)
                .setPosDir(setPosDir)
                .setPushdown(setPushdown)
                .build()
            val data = GrpcConnectionManager.getStub()
                .setRobotJogMove(sendMessage)
        }
    }
}
/******************************************************************************连续运动及步长切换*****/
/*setRobotStepSize*/
class SetRobotStepSizeViewModel2(): ViewModel(){
    init {
        //初始化,告诉服务端当前点动步长
        //println("初始化,向服务端发送:当前点动模式步长为:0.01")
        //setRobotStepSize("setRobotStepSize",0.1)
    }
    var valueChange by mutableStateOf(0)//默认连续运动
    //此处给连续运动
    fun button0(){
        valueChange = 0
    }
    fun button1(){
        valueChange = 1
        setRobotStepSize("setRobotStepSize",1.0)
    }
    fun button2(){
        valueChange = 2
        setRobotStepSize("setRobotStepSize",0.1)
    }
    fun button3(){
        valueChange = 3
        setRobotStepSize("setRobotStepSize",0.01)
    }
    fun modifierChangeColor0(): Int{
        return when(valueChange){
            0-> android.graphics.Color.BLUE
            else-> android.graphics.Color.GRAY
        }
    }
    fun modifierChangeColor1(): Int{
        return when(valueChange){
            1-> android.graphics.Color.BLUE
            else-> android.graphics.Color.GRAY
        }
    }
    fun modifierChangeColor2(): Int{
        return when(valueChange){
            2-> android.graphics.Color.BLUE
            else-> android.graphics.Color.GRAY
        }
    }
    fun modifierChangeColor3(): Int{
        return when(valueChange){
            3-> android.graphics.Color.BLUE
            else-> android.graphics.Color.GRAY
        }
    }
    private fun setRobotStepSize(name: String,value: Double){
        CoroutineScope(Dispatchers.IO).launch {
            val sendMessage = Robot.DoubleMSG.newBuilder()
                .setName(name)
                .setValue(value)
                .build()
            val data = GrpcConnectionManager.getStub()
                .setRobotStepSize(sendMessage)
        }
    }
}
class JogCurSwitchAxis(): ViewModel(){
    var currentAxis = 0
}

JogMoveInterface.kt

package com.hxrobot.ui.teach.PointTeach

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsPressedAsState
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.hxrobot.ui.teach.JogMoveGrpc
import com.hxrobot.ui.teach.SetExAxisJointModeViewModel2
import com.hxrobot.ui.teach.ertherdassdsfsfsf.FontStyle3
import com.hxrobot.ui.teach.ertherdassdsfsfsf.FontStyle5
import com.hxrobot.ui.teach.ertherdassdsfsfsf.colorPaint2

/***********************************************************************************圆柱点动*******/
@Composable
fun JogMoveCylindPointInterface2(){
        Column(
            modifier = Modifier
                .padding(5.dp)
                .fillMaxSize()
            //verticalArrangement = Arrangement.spacedBy(8.dp)
        ) {
            Row(
                modifier = Modifier
                    .weight(1f)
            ) {
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(0,0,false,true,"Z-")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(0,0,true,true,"Z+")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(1,0,false,true,"R-")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(1,0,true,true,"R+")
                }
            }
            Row(
                modifier = Modifier
                    .weight(1f)
            ) {
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(2,0,false,true,"T-")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(2,0,true,true,"T+")
                }
            }
            Row(
                modifier = Modifier
                    .weight(1f)
            ) {
               // FlipChange()
            }
        }

}
/***********************************************************************************关节点动*******/
@Composable
fun JogMoveJointPointInterface2() {
        Column(
            modifier = Modifier
                .padding(5.dp)
                .fillMaxSize()
            //verticalArrangement = Arrangement.spacedBy(8.dp)
        ) {
            Row(
                modifier = Modifier
                    .weight(1f)
            ) {
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(0,0,false,true,"Z-")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(0,0,true,true,"Z+")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(1,0,false,true,"J1-")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(1,0,true,true,"J1+")
                }
            }
            Row(
                modifier = Modifier
                    .weight(1f)
            ) {
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(2,0,false,true,"J2-")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(2,0,true,true,"J2+")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(3,0,false,true,"J3-")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(3,0,true,true,"J3+")
                }
            }
            Row(
                modifier = Modifier
                    .weight(1f)
            ) {
               // FlipChange()
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(4,0,false,true,"Flip-")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(4,0,true,true,"Flip+")
                }
            }

        }

}
/***********************************************************************************笛卡尔点动*******/
@Composable
fun JogMoveCartesianPointInterface2() {
        Column(
            modifier = Modifier
                .padding(5.dp)
                .fillMaxSize()
            //verticalArrangement = Arrangement.spacedBy(8.dp)
        ) {
            Row(
                modifier = Modifier
                    .weight(1f)
            ) {
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(1,0,false,true,"X-")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(1,0,true,true,"X+")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(2,0,false,true,"Y-")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(2,0,true,true,"Y+")
                }
            }
            Row(
                modifier = Modifier
                    .weight(1f)
            ) {
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(0,0,false,true,"Z-")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(0,0,true,true,"Z+")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(3,0,false,true,"Rz-")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(3,0,true,true,"Rz+")
                }
            }
            Row(
                modifier = Modifier
                    .weight(1f)
            ) {
                //FlipChange()
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(4,0,false,true,"Flip-")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveButtonModule(4,0,true,true,"Flip+")
                }
            }

        }

}
/***********************************************************************************圆柱连续运动*******/
@Composable
fun JogMoveCylindContinueInterface2(){
        Column(
            modifier = Modifier
                .padding(5.dp)
                .fillMaxSize()
            //verticalArrangement = Arrangement.spacedBy(8.dp)
        ) {
            Row(
                modifier = Modifier
                    .weight(1f)
            ) {
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveContinueButtonModule(0,false,"Z--")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveContinueButtonModule(0,true,"Z++")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveContinueButtonModule(1,false,"R--")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveContinueButtonModule(1,true,"R++")
                }
            }
            Row(
                modifier = Modifier
                    .weight(1f)
            ) {
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveContinueButtonModule(2,false,"T--")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveContinueButtonModule(2,true,"T++")
                }
            }
            Row(
                modifier = Modifier
                    .weight(1f)
            ) {
               // FlipChange()
            }
        }
}
/***********************************************************************************关节连续运动*******/
@Composable
fun JogMoveJointContinueInterface2() {
    Column(
        modifier = Modifier
            .padding(5.dp)
            .fillMaxSize()
        //verticalArrangement = Arrangement.spacedBy(8.dp)
    ) {
        Row(
            modifier = Modifier
                .weight(1f)
        ) {
            Row(modifier = Modifier.weight(1f)) {
                JogMoveContinueButtonModule(0,false,"Z--")
            }
            Row(modifier = Modifier.weight(1f)) {
                JogMoveContinueButtonModule(0,true,"Z++")
            }
            Row(modifier = Modifier.weight(1f)) {
                JogMoveContinueButtonModule(1,false,"J1--")
            }
            Row(modifier = Modifier.weight(1f)) {
                JogMoveContinueButtonModule(1,true,"J1++")
            }
        }
        Row(
            modifier = Modifier
                .weight(1f)
        ) {
            Row(modifier = Modifier.weight(1f)) {
                JogMoveContinueButtonModule(2,false,"J2--")
            }
            Row(modifier = Modifier.weight(1f)) {
                JogMoveContinueButtonModule(2,true,"J2++")
            }
            Row(modifier = Modifier.weight(1f)) {
                JogMoveContinueButtonModule(3,false,"J3--")
            }
            Row(modifier = Modifier.weight(1f)) {
                JogMoveContinueButtonModule(3,true,"J3++")
            }
        }
        Row(
            modifier = Modifier
                .weight(1f)
        ) {
            //FlipChange()
            Row(modifier = Modifier.weight(1f)) {
                JogMoveContinueButtonModule(4,false,"Flip--")
            }
            Row(modifier = Modifier.weight(1f)) {
                JogMoveContinueButtonModule(4,true,"Flip++")
            }
        }
    }
}
/***********************************************************************************笛卡尔连续运动*******/
@Composable
fun JogMoveCartesianCoutinueInterface2() {
        Column(
            modifier = Modifier
                .padding(5.dp)
                .fillMaxSize()
            //verticalArrangement = Arrangement.spacedBy(8.dp)
        ) {
            Row(
                modifier = Modifier
                    .weight(1f)
            ) {
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveContinueButtonModule(1,false,"X--")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveContinueButtonModule(1,true,"X++")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveContinueButtonModule(2,false,"Y--")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveContinueButtonModule(2,true,"Y++")
                }
            }
            Row(
                modifier = Modifier
                    .weight(1f)
            ) {
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveContinueButtonModule(0,false,"Z--")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveContinueButtonModule(0,true,"Z++")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveContinueButtonModule(3,false,"Rz--")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveContinueButtonModule(3,true,"Rz++")
                }
            }
            Row(
                modifier = Modifier
                    .weight(1f)
            ) {
                //FlipChange()
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveContinueButtonModule(4,false,"Flip--")
                }
                Row(modifier = Modifier.weight(1f)) {
                    JogMoveContinueButtonModule(4,true,"Flip++")
                }
            }
        }
}
/***********************************************************************************工具点动*******/
@Composable
fun JogMoveToolPointInterface2() {
    Column(
        modifier = Modifier
            .padding(5.dp)
            .fillMaxSize()
        //verticalArrangement = Arrangement.spacedBy(8.dp)
    ) {
        Row(
            modifier = Modifier
                .weight(1f)
        ) {
            Row(modifier = Modifier.weight(1f)) {
                JogMoveButtonModule(1, 0, false, true, "X-")
            }
            Row(modifier = Modifier.weight(1f)) {
                JogMoveButtonModule(1, 0, true, true, "X+")
            }
            Row(modifier = Modifier.weight(1f)) {
                JogMoveButtonModule(2, 0, false, true, "Y-")
            }
            Row(modifier = Modifier.weight(1f)) {
                JogMoveButtonModule(2, 0, true, true, "Y+")
            }
        }
    }
}
/***********************************************************************************笛卡尔连续运动*******/
@Composable
fun JogMoveToolCoutinueInterface2() {
    Column(
        modifier = Modifier
            .padding(5.dp)
            .fillMaxSize()
        //verticalArrangement = Arrangement.spacedBy(8.dp)
    ) {
        Row(
            modifier = Modifier
                .weight(1f)
        ) {
            Row(modifier = Modifier.weight(1f)) {
                JogMoveContinueButtonModule(1, false, "X--")
            }
            Row(modifier = Modifier.weight(1f)) {
                JogMoveContinueButtonModule(1, true, "X++")
            }
            Row(modifier = Modifier.weight(1f)) {
                JogMoveContinueButtonModule(2, false, "Y--")
            }
            Row(modifier = Modifier.weight(1f)) {
                JogMoveContinueButtonModule(2, true, "Y++")
            }
        }
    }
}
/************************方便写的按钮JOG组件*****/
@Composable
fun JogMoveButtonModule(setAxis: Int,
                        setMode: Int,
                        setPosDir: Boolean,
                        setPushdown: Boolean,
                        buttonText:String){
    val joveMoveClass: JogMoveGrpc = JogMoveGrpc()
    val lastClickTime = remember { mutableStateOf(0L) }//用于计时,防止重复界面
    Button(onClick = {
        val currentTime = System.currentTimeMillis()
        if (currentTime - lastClickTime.value > 2000) {
            lastClickTime.value = currentTime
            joveMoveClass.jogMoveMessageforSend(setAxis,setMode,setPosDir,setPushdown)
        }
    },
        colors = ButtonDefaults.buttonColors(
            backgroundColor = colorPaint2,
//                contentColor = Color.White,
//                disabledBackgroundColor = Color.Gray,
//                disabledContentColor = Color.DarkGray
        ),
        elevation = ButtonDefaults.elevation(0.dp, 20.dp, 0.dp, 0.dp, 0.dp),
        modifier = Modifier
            .fillMaxSize()
            .padding(10.dp)
    ) {
        Text(text = buttonText, style = FontStyle5)
    }
}
/************************方便写的连续运动按钮JOG组件*****/
@Composable
fun JogMoveContinueButtonModule(setAxis: Int,
                                setPosDir: Boolean,
                                buttonText:String){
    val interactionSource = remember { MutableInteractionSource() }
    val isPressed by interactionSource.collectIsPressedAsState()
    val joveMoveClass: JogMoveGrpc = JogMoveGrpc()
    val lastClickTime = remember { mutableStateOf(0L) }//用于计时,防止重复界面
    if (isPressed){
        //Pressed
        val currentTime = System.currentTimeMillis()
        if(currentTime - lastClickTime.value > 2500){
            println("按下了连续运动按钮")
            joveMoveClass.jogMoveMessageforSend(setAxis,1,setPosDir,true)
            DisposableEffect(Unit) {
                onDispose {
                    //released
                    lastClickTime.value = currentTime
                    joveMoveClass.jogMoveMessageforSend(setAxis,1,setPosDir,false)
                }
            }
        }
    }
    Row(
        modifier = Modifier
            .fillMaxSize()
            .padding(10.dp)
    ) {
        Button(onClick={},
            interactionSource = interactionSource,
            colors = ButtonDefaults.buttonColors(
                backgroundColor = colorPaint2,
//                contentColor = Color.White,
//                disabledBackgroundColor = Color.Gray,
//                disabledContentColor = Color.DarkGray
            ),
            //shape = RoundedCornerShape(20.dp),
            elevation = ButtonDefaults.elevation(0.dp, 20.dp, 0.dp, 0.dp, 0.dp),
            modifier = Modifier
                .fillMaxSize()
                .padding(10.dp)
        ){
            Text(text = buttonText, style = FontStyle5 )
        }
    }
}
@Composable
fun FlipChange(){
    val viewModel: SetExAxisJointModeViewModel2 = viewModel()
    Row() {
        Button(onClick = {
            viewModel.setExAxisJointDecrease()
            println("翻转${-viewModel.setExAxisJointHandle()}")
        }) {
            Text(text = "Flip-", fontSize = 25.sp)
        }
        Button(onClick = {
            viewModel.setExAxisJointAdd()
            println("翻转${viewModel.setExAxisJointHandle()}")
        }) {
            Text(text = "Flip+", fontSize = 25.sp)
        }
    }
}

PointTeachScreen.kt

package com.hxrobot.ui.teach

import RobotGrpc.Robot
import android.annotation.SuppressLint
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.Button
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.material.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import com.google.protobuf.Empty
import com.hxrobot.R
import com.hxrobot.RobotApplication
import com.hxrobot.ui.Jog.RotaryCartesianInterface
import com.hxrobot.ui.Jog.RotaryJointInterface
import com.hxrobot.ui.Jog.RotaryToolInterface
import com.hxrobot.ui.common.PageHeader
import com.hxrobot.ui.teach.PointTeach.*
import com.hxrobot.ui.teach.ertherdassdsfsfsf.*


@Composable
fun PointTeachScreen(navController: NavController,
                     pointNameFromTransfer:String,
                     nameListToString:String,
                     scriptName:String){
    //暂时使用,用于查询点位信息  给出点name
    val nameTransferViewModel: InformationFromPointList3 = viewModel()
    nameTransferViewModel.currentNameFromPointList = pointNameFromTransfer
    //直接传参到点位切换Interface
    //nameListTransferViewModel.currentNameFromPointList = pointNameFromTransfer
    nameTransferViewModel.setCurName(pointNameFromTransfer)//设置curName 然后在其他地方观察
    println("curName是否被设置")
    println(nameTransferViewModel.curNameLiveData.value)

    //发送JOG状态2
    val jogSwitch : SwitchRobotStateClass = SwitchRobotStateClass()
    jogSwitch.switchJogState(2)





    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(all = 6.dp)
    ) {

        Row(modifier = Modifier
            .fillMaxWidth()
            .weight(45f)) {
            PointTeachHeaderInterface(navController,nameTransferViewModel,)
        }
       // 选择点位
        Row(modifier = Modifier
            .fillMaxWidth()
            .weight(45f)) {
            CurrentActionAndPointNameInterface2(nameTransferViewModel,nameListToString,scriptName)
        }
        Row(modifier = Modifier.weight(1f)) {
            CutOffLineTopAndBottomChange()//顶部蓝线
        }
        //功能及显示modifier =Modifier.weight(1f)
        Row(modifier =Modifier.weight(410f)) {
            //当前点位坐标显示/机器人坐标显示
            Column(modifier = Modifier
                .weight(312f)
                .background(
                    Brush.verticalGradient(
                        listOf(Color(0xFF4263BC), Color(0xFF5678E7))
                    )
                )
            ) {
                //当前点位坐标显示
                Row(modifier =Modifier.weight(1f)) {
                    CurrentPointPositionShowInterface2()
                }
                //机器人位置信息显示
                Row(modifier =Modifier.weight(1f)) {
                    RobotPositionShowInterface2()
                }
            }
            //各操作模式
            Column(modifier =Modifier.weight(488f)) {
                //JOG模式切换/坐标显示模式切换
                Row(modifier =Modifier.weight(56f)){
                    Column(modifier =Modifier.fillMaxSize()) {
                        Row(modifier = Modifier.weight(26f)) {
                            Column(modifier =Modifier.weight(130f)) {
                                PositionModeChangeInterface2()
                            }
                            Spacer(modifier = Modifier.weight(70f))
                            //速度设定
                            Column(modifier =Modifier.weight(200f)) {
                                //SetExAxisJointInterface2()
                                SetRobotSpeedRatioInterface2()
                            }
                        }
                    }
                }
                Row(modifier =Modifier.weight(1f)) {
                   //分割线
                    CutOffLineTopUnderModeChange()
                }
                //JOG界面
                Row(modifier =Modifier.weight(296f)) {
                    Column(modifier =Modifier.weight(288f)){
                        Spacer(modifier = Modifier.weight(15f))
                        //200 weigth
                        Row(modifier = Modifier.weight(240f)){
                            Spacer(modifier = Modifier.weight(55f))
                            Column(modifier = Modifier.weight(200f)) {
                                JogMovePageInterface2()
                            }
                            Spacer(modifier = Modifier.weight(33f))
                        }
                        Row(modifier = Modifier.weight(64f)) {
                            Spacer(modifier = Modifier.weight(49f))
                            Column(modifier = Modifier.weight(56f)) {
                                JogButtonLeftInterface()
                            }
                            Spacer(modifier = Modifier.weight(98f))
                            Column(modifier = Modifier.weight(56f)) {
                                JogButtonRightInterface()
                            }
                            Spacer(modifier = Modifier.weight(29f))
                        }
                        Spacer(modifier = Modifier.weight(18f))
                    }
                    Column(modifier =Modifier.weight(200f)){
                        Spacer(modifier = Modifier.weight(50f))
                        //182
                        Row(modifier =Modifier.weight(220f)) {
                            SetRobotStepSizeInterface2()//连续运动/点动步长
                        }
                        Spacer(modifier = Modifier.weight(59f))
                    }
                }
                //运动到点/示教
                Row(modifier =Modifier.weight(40f)) {
                    OperatePointDataInterface2(nameTransferViewModel)
                }
                Spacer(modifier = Modifier.weight(18f))
            }
        }
        Row(modifier = Modifier
            .fillMaxWidth()
            .weight(1f)) {
            CutOffLineTopAndBottomChange()//顶部蓝线
        }
    }
}
/********************************************************************************点位示教界面头******/
@Composable
fun PointTeachHeaderInterface(navController: NavController,nameListTransferViewModel: InformationFromPointList3,){
    PageHeader("${nameListTransferViewModel.currentNameFromPointList}-示教", navController) {
//        Box(
//            modifier = Modifier
//                .fillMaxWidth()
//                .padding(end = 5.dp, start = 5.dp),
//            contentAlignment = Alignment.Center
//        ) {
//        }
    }
}
/**********************************************************************************速度调节界面******/
/*调节机器人速度倍率*/
@SuppressLint("CoroutineCreationDuringComposition")
@Composable
fun SetRobotSpeedRatioInterface2() {
    val speedViewModel: SetRobotSpeedRatioModel = viewModel()
    //val coordinateViewModel: SetRobotCoordinateModeViewModel2 = viewModel()
    val context = LocalContext.current
    val app = context.applicationContext as RobotApplication
    val status: Robot.RobotStatus by app.baseViewModel.robotStatusLiveData.observeAsState(Robot.RobotStatus.getDefaultInstance())
    val curSpeedValue = try {
        status.speedScale
    } catch (e: Exception) {
        // 处理异常,例如记录日志或显示错误消息
        null
    }
    if(curSpeedValue != null){
        speedViewModel.setCurSpeed(curSpeedValue)
    }
//    Row(
//        modifier = Modifier.fillMaxSize()
//    ) {
//        Column(
//            modifier = Modifier
//                .fillMaxSize()
//                .clickable {
//                    speedViewModel.setRobotSpeedChange(coordinateViewModel.coordinateModeValue)
//                }
//        ) {
//            Spacer(modifier = Modifier.weight(15f))
//            Row(modifier = Modifier.weight(26f)) {
//                Row(
//                    modifier = Modifier.weight(70f),verticalAlignment = Alignment.CenterVertically, ) {
//                    Text(text = "速度设定", style = FontStyle8)
//                }
//                Spacer(modifier = Modifier.weight(7f))
//                Row(
//                    modifier = Modifier.weight(42f),verticalAlignment = Alignment.CenterVertically, ) {
//                    Text(text = "${speedViewModel.speed} %", style = FontStyle4)
//                }
//                Spacer(modifier = Modifier.weight(10f))
//                Box(modifier = Modifier.weight(30f)){
//                    Icon(imageVector = ImageVector.vectorResource(id = R.drawable.t_switchicon)
//                        , contentDescription =null,
//                        modifier = Modifier.fillMaxSize(),
//                        tint = Color.Unspecified
//                    )
//                }
//                Spacer(modifier = Modifier.weight(60f))
//            }
//            Spacer(modifier = Modifier.weight(15f))
//        }
//    }

    Row(
        modifier = Modifier
            .fillMaxSize(),
        verticalAlignment = Alignment.CenterVertically
        //horizontalAlignment = Alignment.CenterHorizontally,
        //.border(1.dp, Color.LightGray, RoundedCornerShape(1.dp))
    ){
        Spacer(modifier = Modifier.width((21*1.25).dp))
        Row(modifier = Modifier.width((78*1.25).dp), verticalAlignment = Alignment.CenterVertically){
            Text(text ="速度设定",style = FontStyle8)
        }
        Spacer(modifier = Modifier.width((6*1.25).dp))
        Row(modifier = Modifier.width((52*1.25).dp), verticalAlignment = Alignment.CenterVertically){
            Text(text = "${speedViewModel.speed} %", style = FontStyle4)
        }
        Spacer(modifier = Modifier.width((6*1.25).dp))
        Box(modifier = Modifier.width((50*1.25).dp).padding(1.dp).clip(CircleShape)
            .clickable {
//                speedViewModel.setRobotSpeedChange(coordinateViewModel.coordinateModeValue)
                speedViewModel.setRobotSpeedChange()
            }){
            Icon(imageVector = ImageVector.vectorResource(id = R.drawable.t_switchicon)
                , contentDescription =null,
                modifier = Modifier.fillMaxSize().padding(12.dp),
                tint = Color.Unspecified
            )
        }
        Spacer(modifier = Modifier.width((8*1.25).dp))
    }
}

/***********************************************************************************步长设置界面*****/

/**********************************************************************************翻转轴翻转界面****/
@Composable
fun SetExAxisJointInterface2(){
    val viewModel: SetExAxisJointModeViewModel2 = viewModel()
    viewModel.setExAxisJointHandle()
    Row(
        modifier = Modifier
            .padding(20.dp)
            .border(1.dp, Color.LightGray, RoundedCornerShape(1.dp))
            .height(50.dp)
    ){
        TextField(
            value = viewModel.angleInput,
            onValueChange = { viewModel.angleInput = it },
            modifier = Modifier
                .fillMaxHeight(),
            label = { Text(text = "请输入翻转轴翻转角度")},
            singleLine = true,
            keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
        )
    }
}
/*******************************************************************************JOG模式切换界面******/
/*setRobotCoordinateMode JOG中位姿模式切换界面*/
@Composable
fun SetRobotCoordinateModeInterface2(){
    val viewModel: SetRobotCoordinateModeViewModel2 = viewModel()
    Row(
        modifier = Modifier
            .padding(20.dp)
        //.border(1.dp, Color.LightGray, RoundedCornerShape(1.dp))
    ){
        Row() {
            Text(text =viewModel.changeText(), style = FontStyle4)
            Spacer(modifier = Modifier.padding(8.dp))
            RobotIconTextBtn3(
                imageVector = ImageVector.vectorResource(id = R.drawable.t_switchicon),
                text = "",
                onClick = {
                    viewModel.changeValueButton()
                },
                modifier = Modifier
            )
        }
    }
}
/****************************************jog不同模式显示界面**********/
@Composable
fun JogMovePageInterface2(){
    val viewModelCoordinate: SetRobotCoordinateModeViewModel2 = viewModel()
    Column(modifier = Modifier
        .fillMaxSize()
    ) {
        when(viewModelCoordinate.coordinateModeValue){
            0->RotaryCartesianInterface()
            1-> RotaryJointInterface()
            2->RotaryCartesianInterface()
            3-> RotaryToolInterface()
        }
//        when(viewModelCoordinate.coordinateModeValue){
//            0 -> if (viewModelStepSize.valueChange == 0){
//                Row(modifier = Modifier.weight(1f)) {
//                    JogMoveCylindContinueInterface2()
//                }
//            }else{
//                Row(modifier = Modifier.weight(1f)) {
//                    JogMoveCylindPointInterface2()
//                }
//            }
//            1 -> if (viewModelStepSize.valueChange == 0){
//                Row(modifier = Modifier.weight(1f)) {
//                    JogMoveJointContinueInterface2()
//                }
//            }else{
//                Row(modifier = Modifier.weight(1f)) {
//                    JogMoveJointPointInterface2()
//                }
//            }
//            2 -> if (viewModelStepSize.valueChange == 0){
//                Row(modifier = Modifier.weight(1f)) {
//                    JogMoveCartesianCoutinueInterface2()
//                }
//            }else{
//                Row(modifier = Modifier.weight(1f)) {
//                    JogMoveCartesianPointInterface2()
//                }
//            }
//            3 -> if (viewModelStepSize.valueChange == 0){
//                Row(modifier = Modifier.weight(1f)) {
//                    JogMoveToolCoutinueInterface2()
//                }
//            }else{
//                Row(modifier = Modifier.weight(1f)) {
//                    JogMoveToolPointInterface2()
//                }
//            }
//        }
    }
}
/********************************************************************************位置信息显示界面*****/
/*****************************************************************切换界面******/
@Composable
fun PositionModeChangeInterface2(){
    //val viewModel: PositionModeChangeViewModel2 = viewModel()
    val changeViewModel: SetRobotCoordinateModeViewModel2 = viewModel()
    val context = LocalContext.current
    val app = context.applicationContext as RobotApplication
    val status: Robot.RobotStatus by app.baseViewModel.robotStatusLiveData.observeAsState(Robot.RobotStatus.getDefaultInstance())
    val curOperateModeValue = try {
        status.jogOperateMode
    } catch (e: Exception) {
        // 处理异常,例如记录日志或显示错误消息
        null
    }
    if(curOperateModeValue != null){
        changeViewModel.getServerModeAndSet(curOperateModeValue)
    }
//    Row(
//        modifier = Modifier
//            .padding(20.dp)
//            .border(1.dp, Color.LightGray, RoundedCornerShape(1.dp))
//    ){
//        Text(text = viewModel.changeText(), fontSize = 24.sp)
//        Spacer(modifier = Modifier.padding(15.dp))
//        Button(onClick = {
//            viewModel.changeValueButton()
//        }
//        ) {
//            Text(text = "切换", fontSize = 24.sp)
//        }
//    }
//    Column(
//        modifier = Modifier
//            .fillMaxSize()
//            .clickable {
//                changeViewModel.changeValueButton()
//            },
//        horizontalAlignment = Alignment.CenterHorizontally,
//            //.border(1.dp, Color.LightGray, RoundedCornerShape(1.dp))
//    ){
//        Spacer(modifier = Modifier.weight(15f))
//        Row(modifier = Modifier.weight(26f)) {
//            Row(modifier = Modifier
//                .fillMaxSize()
//                ) {
//                Spacer(modifier = Modifier.weight(20f))
//                Row(
//                    modifier = Modifier.weight(55f),verticalAlignment = Alignment.CenterVertically, ) {
//                    Text(text =changeViewModel.changeText(),style = FontStyle4)
//                }
//                Box(modifier = Modifier.weight(24f)){
//                    Icon(imageVector = ImageVector.vectorResource(id = R.drawable.t_switchicon)
//                        , contentDescription =null,
//                        modifier = Modifier.fillMaxSize(),
//                        tint = Color.Unspecified
//                    )
//                }
//                //Spacer(modifier = Modifier.weight(15f))
//            }
//        }
//        Spacer(modifier = Modifier.weight(15f))
//       // Spacer(modifier = Modifier.weight(15f))
//    }


    Row(
        modifier = Modifier
            .fillMaxSize(),
        verticalAlignment = Alignment.CenterVertically
        //horizontalAlignment = Alignment.CenterHorizontally,
        //.border(1.dp, Color.LightGray, RoundedCornerShape(1.dp))
    ){
        Spacer(modifier = Modifier.width((21*1.25).dp))
        Row(modifier = Modifier.width((78*1.25).dp), verticalAlignment = Alignment.CenterVertically){
            Text(text =changeViewModel.changeText(),style = FontStyle4)
        }
        Spacer(modifier = Modifier.width((6*1.25).dp))
        Box(modifier = Modifier.width((50*1.25).dp).padding(1.dp).clip(CircleShape)
            .clickable {
            changeViewModel.changeValueButton()
        }){
            Icon(imageVector = ImageVector.vectorResource(id = R.drawable.t_switchicon)
                , contentDescription =null,
                modifier = Modifier.fillMaxSize().padding(12.dp),
                tint = Color.Unspecified
            )
        }
        Spacer(modifier = Modifier.width((8*1.25).dp))
        }
}
///*****************************************************位置(圆柱/坐标/关节)显示*******/
//@Composable
//fun RobotPositionShowInterface2(){
//    val viewModel: PositionModeChangeViewModel2 = viewModel()
//    Column(modifier = Modifier
        .height(400.dp)
        .width(500.dp)
//        .fillMaxSize()
//    ) {
//        when(viewModel.positionModeValue){
//            //1 -> CylindPositionShowInterface2()
//            1-> CylindPositionShowInterface2()
//            2 -> JointPositionShowInterface2()
//            else -> CartesianPositionShowInterface2()
//        }
//    }
//}
///******************************位置显示子界面******/
//@Composable
//fun CylindPositionShowInterface2() {
//    val context = LocalContext.current
//    val app = context.applicationContext as RobotApplication
//    val status: Robot.RobotStatus by app.baseViewModel.robotStatusLiveData.observeAsState(Robot.RobotStatus.getDefaultInstance())
//    val stringlistCylind: Array<String> = arrayOf("R ", "T ", "Z ","   ","   ","   ")
//    Column() {
//        Text(text = "机器人当前位置(圆柱值)", fontSize = 24.sp,
//            modifier = Modifier
//                .fillMaxWidth()
//                .background(color = Color.Gray))
//        repeat(3) {
//            Row(
//            ) {
//                Text(
//                    text = "${stringlistCylind.getOrNull(it)}    ${
//                        String.format(
//                            "%1.3f",
//                            status.cylindFeedbackPosList.getOrNull(it)
//                        )
//                    }",
//                    fontSize = 30.sp
//                )
//            }
//        }
//    }
//}
//@Composable
//fun CartesianPositionShowInterface2() {
//    val context = LocalContext.current
//    val app = context.applicationContext as RobotApplication
//    val status: Robot.RobotStatus by app.baseViewModel.robotStatusLiveData.observeAsState(Robot.RobotStatus.getDefaultInstance())
//    val stringlistCartes: Array<String> = arrayOf("X  ", "Y  ", "Z  ", "Rx", "Ry", "Rz")
//    Column() {
//        Text(text = "机器人当前位置(位姿值)", fontSize = 24.sp,
//            modifier = Modifier
//                .fillMaxWidth()
//                .background(color = Color.Gray))
//        repeat(6) {
//            Row(
//            ) {
//                Text(
//                    text = "${stringlistCartes.getOrNull(it)}    ${
//                        String.format(
//                            "%1.3f",
//                            status.cartesFeedbackPosList.getOrNull(it)
//                        )
//                    }",
//                    fontSize = 30.sp
//                )
//            }
//        }
//    }
//}
//@Composable
//fun JointPositionShowInterface2() {
//    val context = LocalContext.current
//    val app = context.applicationContext as RobotApplication
//    val status: Robot.RobotStatus by app.baseViewModel.robotStatusLiveData.observeAsState(Robot.RobotStatus.getDefaultInstance())
//    val stringlistJoint: Array<String> = arrayOf("Z  ", "J2 ", "J3 ", "J4 ", "Flip ", "J6 ")
//    Column() {
//        Text(text = "机器人当前位置(关节值)", fontSize = 24.sp,
//            modifier = Modifier
//                .fillMaxWidth()
//                .background(color = Color.Gray))
//        repeat(6) {
//            Row(
//            ) {
//                Text(
//                    text = "${stringlistJoint.getOrNull(it)}    ${
//                        String.format(
//                            "%1.3f",
//                            status.jointsFeedbackPosList.getOrNull(it)
//                        )
//                    }",
//                    fontSize = 30.sp
//                )
//            }
//        }
//    }
//}
/*****************************************************************************点位goto/取消/示教*****/
@Composable
fun OperatePointDataInterface2(nameListTransferViewModel: InformationFromPointList3,){
    val viewModel: CurrentPointInformationViewModel2 = viewModel()
    val operatePointDataClass = OperatePointDataClass2()
    val nameChangeViewModel: InformationFromPointList3 = viewModel()//从上方获取到当前的点位名称

    Row(modifier = Modifier
        .fillMaxSize()) {
        //goto
       // Spacer(modifier = Modifier.padding(40.dp))
//        Button(onClick = {
//            operatePointDataClass.gotoButton(viewModel.currentNameFromPointList,"0")},)
//        {
//            if (viewModel.currentNameFromPointList != "nullName"){
//                Text(text = "Go to", fontSize = 30.sp)
//            }else{
//                Text(text = "Go to", fontSize = 30.sp,color = Color.Gray)
//            }
//        }
        Spacer(modifier = Modifier.weight(16f))
        PlainButton2(modifier = Modifier
            .weight(150f)
            , onClick = {
                if(viewModel.firstGetByPointNameIndex == (nameChangeViewModel.curNameLiveData.value
                        ?: "nullName")
                ){
                    operatePointDataClass.cancelButton(nameChangeViewModel.curNameLiveData.value?:"nullName",viewModel.firstGetByPointValue)
                    viewModel.showPointData(nameChangeViewModel.curNameLiveData.value?:"nullName")
                }
            }
        ){
            if (viewModel.currentNameFromPointList != "nullName"){
                Text(text = "取消示教", style = FontStyle7)
            }else{
                Text(text = "取消示教", style = FontStyle7, color = Color.Gray)
            }
        }
        Spacer(modifier = Modifier.weight(4f))
        val speedViewModel: SetRobotSpeedRatioModel = viewModel()//为运动到点添加速度
        PlainButton2(modifier = Modifier
            .weight(148f)
            , onClick = {
                operatePointDataClass.gotoButton(nameChangeViewModel.curNameLiveData.value?:"nullName","${speedViewModel.speed}")
            }
        ){
            if (viewModel.currentNameFromPointList != "nullName"){
                Text(text = "运动到点", style = FontStyle7)
            }else{
                Text(text = "运动到点",style = FontStyle7 ,color = Color.Gray)
            }
        }
        Spacer(modifier = Modifier.weight(4f))
        PlainButton2(modifier = Modifier
            .weight(150f) ,
            onClick = {
                //此处采用runblocking的方法将通讯挂起,否则重新查询点位信息时
                operatePointDataClass.teachButton(nameChangeViewModel.curNameLiveData.value?:"nullName","0")
                viewModel.showPointData(nameChangeViewModel.curNameLiveData.value?:"nullName")
                viewModel.firstGetByPointNameIndex = nameChangeViewModel.curNameLiveData.value?:"nullName"
            }
        ){
            if (viewModel.currentNameFromPointList != "nullName"){
                Text(text = "示 教", style = FontStyle7)
            }else{
                Text(text = "示 教",style = FontStyle7 ,color = Color.Gray)
            }
        }
        Spacer(modifier = Modifier.weight(16f))
//        //取消
//        Spacer(modifier = Modifier.padding(40.dp))
//        Button(onClick = { /*TODO*/ },) {
//            if (viewModel.currentNameFromPointList != "nullName"){
//                Text(text = "示 教", fontSize = 30.sp)
//            }else{
//                Text(text = "示 教",fontSize = 30.sp ,color = Color.Gray)
//            }
//        }
//        //示教
//        Spacer(modifier = Modifier.padding(40.dp))
//        Button(onClick = {
//            //此处采用runblocking的方法将通讯挂起,否则重新查询点位信息时
//            operatePointDataClass.teachButton(nameChangeViewModel.curNameLiveData.value?:"nullName","0")
//            viewModel.showPointData(nameChangeViewModel.curNameLiveData.value?:"nullName")
//        },) {
//            if (viewModel.currentNameFromPointList != "nullName"){
//                Text(text = "示 教", fontSize = 30.sp)
//            }else{
//                Text(text = "示 教",fontSize = 30.sp ,color = Color.Gray)
//            }
//        }
    }
}
/****************************************************************************当前动作/当前点位 界面*****/
@Composable
fun CurrentActionAndPointNameInterface2(nameListTransferViewModel: InformationFromPointList3,nameListToString:String,scriptName:String){
    //val pointCurNameViewMode: RobotPointNameViewModel = viewModel()
    //
    //val nameChangeViewModel: InformationFromPointList3 = viewModel()
    //
//    val viewModel: CurrentPointInformationViewModel2 = viewModel()
//    viewModel.currentNameFromPointList = nameChangeViewModel.currentNameFromPointList
//    viewModel.currentNameFromPointList ="point1"


    //nameChangeViewModel.currentNameFromPointList = "point1"
    Row(
        modifier = Modifier.fillMaxWidth()
        //.border(2.dp, Color.LightGray, RoundedCornerShape(2.dp))
    ) {
//        Spacer(modifier = Modifier.width(20.dp))
//        Text(text = "当前动作", fontSize = 24.sp)
//        Spacer(modifier = Modifier.width(30.dp))
//        Text(text = "点位名称:      ${nameListTransferViewModel.currentNameFromPointList}", fontSize = 24.sp)
//        Spacer(modifier = Modifier.width(300.dp))
//        Button(onClick = { nameListTransferViewModel.toLastPoint(nameListToString)
//            },
//        modifier = Modifier.weight(2f)) {
//            Text(text = "上一点位")
//        }
//        Spacer(modifier = Modifier.weight(1f))
//
//        Button(onClick = { nameListTransferViewModel.toNextPoint(nameListToString)},
//            modifier = Modifier.weight(2f)) {
//            Text(text = "下一点位")
//        }
//        Column(horizontalAlignment =Alignment.End,
//            modifier = Modifier.weight(13f)) {
//            Text(text = scriptName, style =  PageRowTitleStyleBlackRight)
//        }
        Column(modifier = Modifier.fillMaxSize()) {
            Spacer(modifier = Modifier.weight(2f))
            Row(modifier = Modifier.weight(36f)) {
                Spacer(modifier = Modifier.weight(48f))
                PlainButton2(modifier = Modifier
                    .weight(86f) ,
                    onClick = {
                    nameListTransferViewModel.toLastPoint(nameListToString)
                }){
                    Text(text = "上一点位", style = FontStyle7)
                }
                Spacer(modifier = Modifier.weight(4f))
                PlainButton2(modifier = Modifier
                    .weight(86f) ,
                    onClick = {
                    nameListTransferViewModel.toNextPoint(nameListToString)
                }){
                    Text(text = "下一点位",style = FontStyle7 )
                }
                Column(horizontalAlignment =Alignment.End,
                    modifier = Modifier.weight(560f)) {
                    Text(text = scriptName, style =  PageRowTitleStyleBlackRight)
                }
                Spacer(modifier = Modifier.weight(16f))
            }
            Spacer(modifier = Modifier.weight(8f))
        }
    }
}
/************************************分割栏*****/
@Composable
fun CutOffLineTopUnderModeChange(){
    Row(modifier = Modifier
        .fillMaxSize()
        .background(Color.Unspecified)
        //.border(width = 2.dp, brush = Brush.horizontalGradient(),shape = RoundedCornerShape(1.dp))
    ){
        Column(modifier = Modifier
            .weight(16f)
            .fillMaxHeight()
            .background(Color.Unspecified)) {
        }
        Column(modifier = Modifier
            .weight(456f)
            .fillMaxHeight()
            .background(Color(0xFFD0D2D5))) {
        }
        Column(modifier = Modifier
            .weight(16f)
            .fillMaxHeight()
            .background(Color.Unspecified)) {
        }
    }
}
/************************************分割栏top和Bottom*****/
@Composable
fun CutOffLineTopAndBottomChange(){
    Row(modifier = Modifier
        .fillMaxSize()
        .background(Color(0xFF5678E7))
        //.border(width = 2.dp, brush = Brush.horizontalGradient(),shape = RoundedCornerShape(1.dp))
    ){
    }
}
///***************************************************************************当前选中点位的信息界面*****/
//@Composable
//fun CurrentPointPositionShowInterface2(){
//    val interfaceChangeViewModel: PositionModeChangeViewModel2 = viewModel()//切换不同显示模式
//    val viewModelForPoint: CurrentPointInformationViewModel2 = viewModel()//当前点位信息操作
//    val nameChangeViewModel: InformationFromPointList3 = viewModel()//从上方获取到当前的点位名称

  val curName by nameChangeViewModel.curNameLiveData.observeAsState("nullName")
//    //判断当前位置有无改变viewModelForPoint.currentNameFromPointList  nameChangeViewModel.currentNameFromPointList,
    val isChanged by remember() {
        derivedStateOf { nameChangeViewModel.currentNameFromPointList != viewModelForPoint.currentNameFromPointList }
    }
//    //若点位变了,切换点位,重新获取
    if(nameChangeViewModel.currentNameFromPointList != viewModelForPoint.currentNameFromPointList){
        viewModelForPoint.currentNameFromPointList = nameChangeViewModel.currentNameFromPointList
        if(viewModelForPoint.currentNameFromPointList != "nullName"){
            viewModelForPoint.showPointData()
        }
    }
//    val curName by nameChangeViewModel.curNameLiveData.observeAsState("nullName")
//    //viewModelForPoint.currentNameFromPointList = nameChangeViewModel.c
//    //viewModelForPoint.showPointData(nameChangeViewModel.curNameLiveData.value?:"nullName")
//      viewModelForPoint.showPointData(curName)
//
        val isChanged by remember(curName) {
        derivedStateOf { curName!=viewModelForPoint.currentNameFromPointList }
    }
//
    if(curName!=viewModelForPoint.currentNameFromPointList){

    }
    val isChanged by remember(curName) {
        derivedStateOf { curName!=viewModelForPoint.currentNameFromPointList }
    }
    if(isChanged){
        //viewModelForPoint.currentNameFromPointList = curName
        viewModelForPoint.showPointData()
    }
    when (isChanged) {
        true -> {curName!=viewModelForPoint.currentNameFromPointList}
        else -> Color.Unspecified
    }
//
    val isClicked by remember(curName) {
        derivedStateOf { curName==item.name }
    }
    println("当前选中点位的信息界面")
    println(nameChangeViewModel.currentNameFromPointList)
//
//    //实际上此处应该把实际处理完的所有值作为观察对象,应该观察用于显示在界面上的数据
//     //监控获取到的数据,若为空,重新获取并刷新界面
//     val getGrpcValue by viewModelForPoint.robotPointValueListLiveData.observeAsState(null)
//    if(getGrpcValue == null){
//        viewModelForPoint.showPointData(curName)
//    }
//    //显示点位
//    //viewModelForPoint.putNameIn("point1")
//
//    Column(modifier = Modifier
//        .width(500.dp)
//        .height(300.dp)) {
//        Text(text = "当前点位位置    (${interfaceChangeViewModel.changeText()})", fontSize = 24.sp,
//            modifier = Modifier
//                .fillMaxWidth()
//                .background(color = Color.Gray))
//        if(interfaceChangeViewModel.positionModeValue == 1){
//            PointPositionShowCompose(viewModelForPoint.stringlistExtJoint,
//                viewModelForPoint.posListOfExtJoint,
//                viewModelForPoint.stringlistCylind,
//                viewModelForPoint.posListOfCylind,
//            3)
//        }
//        else if(interfaceChangeViewModel.positionModeValue == 2){
//            PointPositionShowCompose(viewModelForPoint.stringlistExtJoint,
//                viewModelForPoint.posListOfExtJoint,
//                viewModelForPoint.stringlistJoint,
//                viewModelForPoint.posListOfJoints,
//            6)
//        }else{
//            PointPositionShowCompose(viewModelForPoint.stringlistExtJoint,
//                viewModelForPoint.posListOfExtJoint,
//                viewModelForPoint.stringlistCartes,
//                viewModelForPoint.posListOfCartes,
//            6)
//        }
//    }
//}
///********************点位信息的子界面组件************/
//@Composable
//fun  PointPositionShowCompose(extjName :Array<String>,
//                              extjValue: MutableList<Double>,
//                              elementName:Array<String>,
//                              elementValue: MutableList<Double>,
//                              elementCount: Int){
//    Column() {
//        repeat(2) {
//            Row(
//            ) {
//                Text(
//                    text = "${extjName.getOrNull(it)}    ${
//                        String.format(
//                            "%1.3f",
//                            extjValue.getOrNull(it)
//                        )
//                    }",
//                    fontSize = 24.sp
//                )
//            }
//        }
//        repeat(elementCount) {
//            Row(
//            ) {
//                Text(
//                    text = "${elementName.getOrNull(it)}    ${
//                        String.format(
//                            "%1.3f",
//                            elementValue.getOrNull(it)
//                        )
//                    }",
//                    fontSize = 24.sp
//                )
//            }
//        }
//    }
//}



///

PointTeachViewModel.kt

package com.hxrobot.ui.teach

import RobotGrpc.Robot
import RobotGrpc.Robot.Cartesian
import android.annotation.SuppressLint
import android.graphics.Color
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.hxrobot.data.GrpcConnectionManager
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.jsonObject

import org.json.JSONObject


//函数-用于发送jogMove信息
class JogMoveGrpc(){
    fun jogMoveMessageforSend(
        setAxis: Int,
        setMode: Int,
        setPosDir: Boolean,
        setPushdown: Boolean,
    ){
        CoroutineScope(Dispatchers.IO).launch {
            val sendMessage = Robot.JogMove.newBuilder()
                .setAxis(setAxis)
                .setMode(setMode)
                .setPosDir(setPosDir)
                .setPushdown(setPushdown)
                .build()
            val data = GrpcConnectionManager.getStub()
                .setRobotJogMove(sendMessage)
        }
    }
}
/********************************************************************向服务端发送当前状态为JOG状态*****/
class SwitchRobotStateClass(){
    fun switchJogState(state:Int){
        switchRobotState(state)
    }
    private fun switchRobotState(state:Int){
        CoroutineScope(Dispatchers.IO).launch {
            val sendMessage = Robot.SwitchState.newBuilder()
                .setState(state)
                .build()
            val data = GrpcConnectionManager.getStub()
                .switchRobotState(sendMessage)
        }
    }
}
/**********************************************************************************速度倍率设设置******/
class SetRobotSpeedRatioModel(): ViewModel() {
    init {
//        //初始化,告诉服务端当前速度倍率
//        println("初始化,向服务端发送:当前速度倍率为:0.2")
//        setRobotSpeedRatio(0.2)
        //setRobotSpeedChange(2)
    }
    var speed by mutableStateOf(20)

//    val curSpeedLiveData: LiveData<Int>
//        get() = curSpeed
//    private var curSpeed = MutableLiveData<Int>()
    fun setCurSpeed(speed:Double){
        this.speed = (speed *100).toInt();
    }

//    fun setRobotSpeedChange(index:Int,){
//        if(index == 0){
//            sendRobCoordinateMode("Cylindrical",1)
//            setRobotSpeedRatio(handleSpeedChangeRange(speed))
//            sendRobCoordinateMode("Cylindrical",0)
//        }
//        if(index == 1){
//            sendRobCoordinateMode("Joint",2)
//            setRobotSpeedRatio(handleSpeedChangeRange(speed))
//            sendRobCoordinateMode("Joint",1)
//        }
//        if(index == 2){
//            sendRobCoordinateMode("Cartesian",1)
//            setRobotSpeedRatio(handleSpeedChangeRange(speed))
//            sendRobCoordinateMode("Cartesian",2)
//        }
//        if(index == 3){
//            sendRobCoordinateMode("tool",2)
//            setRobotSpeedRatio(handleSpeedChangeRange(speed))
//            sendRobCoordinateMode("tool",3)
//        }
//    }
fun setRobotSpeedChange(){
        setRobotSpeedRatio(handleSpeedChangeRange(speed))
}
    fun handleSpeedChangeRange(speedInt:Int):Double{
        if (speedInt!= 100&&speedInt!= 70&&speedInt!= 50&&speedInt!= 20&&speedInt!= 5){
            this.speed = 20
        }
        if (speedInt ==5){
            this.speed = 20
        }
        if (speedInt == 20){
            this.speed = 50
        }
        if (speedInt == 50){
            this.speed = 70
        }
        if (speedInt == 70){
            this.speed = 100
        }
        if (speedInt == 100){
            this.speed = 5
        }
        return (this.speed.toDouble()/100)
    }
//    fun setRobotSpeedRatioUp(){
//        this.speed += 10
//        if(speed >100){
//            speed = 100
//        }
//        val speedRatio = (speed.toDouble()/100)
//        setRobotSpeedRatio(speedRatio)
//    }
//    fun setRobotSpeedRatioDown(){
//        this.speed -= 10
//        if(speed <0 ){
//            speed = 0
//        }
//        val speedRatio = (speed.toDouble()/100)
//        setRobotSpeedRatio(speedRatio)
//    }
    private fun sendRobCoordinateMode(name: String,value: Int){
        CoroutineScope(Dispatchers.IO).launch {
            val sendMessage = Robot.Int32MSG.newBuilder()
                .setName(name)
                .setValue(value)
                .build()
            val data = GrpcConnectionManager.getStub()
                .setRobotCoordinateMode(sendMessage)
        }
    }
    private fun setRobotSpeedRatio(speedRatio:Double){
        CoroutineScope(Dispatchers.IO).launch {
            val sendMessage = Robot.DoubleMSG.newBuilder().setValue(speedRatio).build()
            val data = GrpcConnectionManager.getStub()
                .setRobotSpeedRatio(sendMessage)
        }
    }
}
/******************************************************************************连续运动及步长切换*****/
/*setRobotStepSize*/
class SetRobotStepSizeViewModel2(): ViewModel(){
    init {
        //初始化,告诉服务端当前点动步长
        println("初始化,向服务端发送:当前点动模式步长为:0.01")
        setRobotStepSize("setRobotStepSize",0.01)
    }
    var valueChange by mutableStateOf(3)
    //此处给连续运动
    fun button0(){
        valueChange = 0
    }
    fun button1(){
        valueChange = 1
        setRobotStepSize("setRobotStepSize",1.0)
    }
    fun button2(){
        valueChange = 2
        setRobotStepSize("setRobotStepSize",0.1)
    }
    fun button3(){
        valueChange = 3
        setRobotStepSize("setRobotStepSize",0.01)
    }
    fun modifierChangeColor0(): Int{
        return when(valueChange){
            0-> Color.BLUE
            else-> Color.GRAY
        }
    }
    fun modifierChangeColor1(): Int{
        return when(valueChange){
            1-> Color.BLUE
            else-> Color.GRAY
        }
    }
    fun modifierChangeColor2(): Int{
        return when(valueChange){
            2-> Color.BLUE
            else-> Color.GRAY
        }
    }
    fun modifierChangeColor3(): Int{
        return when(valueChange){
            3-> Color.BLUE
            else-> Color.GRAY
        }
    }
    private fun setRobotStepSize(name: String,value: Double){
        CoroutineScope(Dispatchers.IO).launch {
            val sendMessage = Robot.DoubleMSG.newBuilder()
                .setName(name)
                .setValue(value)
                .build()
            val data = GrpcConnectionManager.getStub()
                .setRobotStepSize(sendMessage)
        }
    }
}
/************************************************************************************翻转轴翻转******/
/*setExAxisJoint*/
class SetExAxisJointModeViewModel2(): ViewModel(){
    var angleInput by mutableStateOf("180.0")
    fun setExAxisJointHandle(): Double{
        var angle = angleInput.toDoubleOrNull() ?: null
        if(angle == null){
            angle = 0.0
            angleInput = ""
        }
        if(angle >180){
            angle = 180.0
            angleInput = "180.0"
        }
        if(angle <0 ){
            angle = 0.0
            angleInput = "0.0"
        }
        return angle
    }
    fun setExAxisJointAdd(){
        setExAxisJoint("setExAxisJoint",setExAxisJointHandle())
    }
    fun setExAxisJointDecrease(){
        setExAxisJoint("setExAxisJoint",-setExAxisJointHandle())
    }
    fun setExAxisJoint(name: String,value: Double){
        CoroutineScope(Dispatchers.IO).launch {
            val sendMessage = Robot.DoubleMSG.newBuilder()
                .setName(name)
                .setValue(value)
                .build()
            val data = GrpcConnectionManager.getStub()
                .setExAxisJoint(sendMessage)
        }
    }
}
/************************************************************************************jog模式切换*****/
/*setRobotCoordinateMode*/
class SetRobotCoordinateModeViewModel2(): ViewModel(){
    init {
//        //初始化,告诉服务端切换至笛卡尔模式
//        println("初始化,向服务端发送:JOG模式为3,笛卡尔模式")
//        sendRobCoordinateMode("sendRobCoordinateMode",1)
    }
    var coordinateModeValue by mutableStateOf(1)
    fun getServerModeAndSet(serverJogOperateMode:Int){
        coordinateModeValue = serverJogOperateMode
    }
    fun changeText(): String{
        return when(coordinateModeValue){
            0-> "圆柱模式"
            1-> "关节模式"
            2-> "位姿模式"
            3-> "工具模式"
            else -> "error"
        }
    }
    //按钮切换,切换后发送模式变化指令
    fun changeValueButton(){
        if (coordinateModeValue == 3)
        {
            coordinateModeValue = 1
        }
        else{
            coordinateModeValue += 1
        }
        sendRobCoordinateMode("sendRobCoordinateMode",coordinateModeValue)
    }
    private fun sendRobCoordinateMode(name: String,value: Int){
        CoroutineScope(Dispatchers.IO).launch {
            val sendMessage = Robot.Int32MSG.newBuilder()
                .setName(name)
                .setValue(value)
                .build()
            val data = GrpcConnectionManager.getStub()
                .setRobotCoordinateMode(sendMessage)
        }
    }
}
/*****************************************************************************坐标显示模式切换******/
class PositionModeChangeViewModel2(): ViewModel(){
    var positionModeValue by mutableStateOf(1)
    fun changeText(): String{
        return when(positionModeValue){
//            1-> "圆柱值"
//            2-> "关节值"
//            else-> "位姿值"
            0->"圆柱值"
            1-> "关节值"
            2-> "位姿值"
            else-> "圆柱值"
        }
    }
    //按钮切换,切换后发送模式变化指令
    fun changeValueButton(){
        if (positionModeValue == 2)
        {
            positionModeValue = 1
        }
        else{
            positionModeValue += 1
        }
    }
}
/****************************************************************************************示教******/
class OperatePointDataClass2(){
    /*************************示教*******/
    fun teachButton(setName: String,setValue: String){
        if(setName != "nullName"){
            teachRobotPointData(setName,setValue)
            println("示教点为${setName}")
        }else{
            println("未指定示教点")
        }
    }
    private fun teachRobotPointData(name: String,value: String){
        runBlocking{
            val sendMessage = Robot.StringMSG.newBuilder()
                .setName(name)
                .setValue(value)
                .build()
            val data = GrpcConnectionManager.getStub()
                .teachRobotPointData(sendMessage)
            println("发送的示教信息")
            println("示教点位${name}")
            println("示教值${value}")
        }
    }
    /*********************************goto*********/
    fun gotoButton(setName: String,setValue: String){
        if(setName != "nullName"){
            gotoJogPoint(setName,setValue)
            println("goto点为${setName}")
        }else{
            println("未指定示教点")
        }
    }
    private fun gotoJogPoint(name: String,value: String){
        runBlocking{
            val sendMessage = Robot.StringMSG.newBuilder()
                .setName(name)
                .setValue(value)
                .build()
            val data = GrpcConnectionManager.getStub()
                .gotoJogPoint(sendMessage)
        }
    }
    /*********************************取消*********/
    fun cancelButton(setName: String,setValue: String){
        if(setName != "nullName"){
            cancelJogPoint(setName,setValue)
            println("设置点为${setName}")
        }else{
            println("未指定示教点")
        }
    }
    private fun cancelJogPoint(name: String,value: String){
        runBlocking{
            val sendMessage = Robot.StringMSG.newBuilder()
                .setName(name)
                .setValue(value)
                .build()
//            println("292929292929292929292929292929")
//            println(name)
//            println(value)
            val data = GrpcConnectionManager.getStub()
                .setRobotPointData(sendMessage)
        }
    }
}
/****************************************************************************点位名称viewmodel*****/
@SuppressLint("MutableCollectionMutableState")
class CurrentPointInformationViewModel2(): ViewModel() {
    init {
        //putNameIn()
    }
    //将点位名称初始化为nullName
    //var currentNameFromPointList by mutableStateOf("nullName")
    //var currentNameFromPointList by mutableStateOf("nullName")
    var currentNameFromPointList = "nullname"
    //不同显示模式下的点的信息名称数组
    val stringlistExtJoint: Array<String> = arrayOf("ExtJ1 ", "ExtJ2 ")
    val stringlistCylind: Array<String> = arrayOf("R ", "T ", "Z ","   ","   ","   ")
    val stringlistJoint: Array<String> = arrayOf("J1 ", "J2 ", "J3 ", "J4 ", "J5 ", "J6 ")
    val stringlistCartes: Array<String> = arrayOf("X  ", "Y  ", "Z  ", "Rx", "Ry", "Rz")
    //建立列表,用于加载点位数据后显示
    val posListOfExtJoint by mutableStateOf(mutableListOf<Double>())
    val posListOfCartes  by mutableStateOf(mutableListOf<Double>())
    val posListOfJoints by mutableStateOf(mutableListOf<Double>())
    val posListOfCylind by mutableStateOf(mutableListOf<Double>())
    var pointConfig by mutableStateOf(1.0)
    var pointIntroduction by mutableStateOf("")
    var pointTeached by mutableStateOf(false)


    //保留初始接收的字符串,若取消示教操作,直接返还该字符串
    var firstGetByPointValue = "pointValue"
    var firstGetByPointValueIndex = true
    var firstGetByPointNameIndex = "null"
    //更新和获取点位数据并显示在界面上
    fun showPointData2(){
        //putNameIn()//获取名称
        //getCurrentPointValue()//根据点位名称向服务端查询String的pointData值
                              //获取后进行string提取,字符串JSON解析,解析后赋值给一个list

        //testJson()
//        if(robotPointValueStr.value != null){
//            jsonHandle(robotPointValueStr.value!!.value)
//        }
        //putValueIn()//用于显示在界面上的数据
        //testJson2()

    }
    fun showPointData(currentName:String){
        if(currentName!= "nullName"){
            getCurrentPointValue(currentName)
        }else{
            println("当前要获取的点位名称为nullName,未获取到名称")
        }

    }
//    val curNameLiveData:LiveData<String>
//        get() = curName
//    private var curName = MutableLiveData<String>()
//    fun setCurrentPointName(name: String){
//        curName.value = name
//    }

    //将点value值放入
//    fun putValueIn(){
//        for (i in 0 until 1) {
//            posListOfExtJoint.add(i, 0.0)
//        }
//        for (i in 0 until 2) {
//            posListOfCartes.add(i,2.0 )
//        }
//        for (i in 0 until 5) {
//            posListOfJoints.add(i,3.0)
//        }
//        for (i in 0 until 5) {
//            posListOfCylind.add(i, 4.0)
//        }
        for (i in 0 until 16) {
            posListOfExtJoint.add(
                Json.decodeFromString("""{
                    "${}",
                }""")
            )
        }
//
//    }
//    fun testJson2(): PointData{
//        val pointDataOb :PointData = PointData()
//        val pointFromJson = Json{ignoreUnknownKeys = true}.decodeFromString<PointData>("""{\"Cartesian\":{\"Rx\":0.0,\"Ry\":0.0,\"Rz\":0.0,\"X\":0.0,\"Y\":0.0,\"Z\":0.0},\"Config\":-858993460,\"Cylindrical\":{\"J234\":0.0,\"R\":0.0,\"T\":0.0,\"Z\":0.0},\"Extj1\":0.0,\"Extj2\":0.0,\"Joint\":{\"Joint1\":78.0,\"Joint2\":88.0,\"Joint3\":98.0,\"Joint4\":0.0,\"Joint5\":0.0,\"Joint6\":0.0}}""".trimMargin())
//        println("JOSN获取到了吗")
//        println(pointDataOb.Joint.Joint1)
//        return pointFromJson
//    }
    //将点名称放入
    fun putNameIn(pointName: String){
        currentNameFromPointList = pointName
    }
    val robotPointValueListLiveData: LiveData<Robot.DataReplyMSG>
        get() = robotPointValueStr
    private val robotPointValueStr = MutableLiveData<Robot.DataReplyMSG>()

//    val robotPointDataFromServerLiveData: LiveData<MutableList<Double>>
//        get() = dataFromServer
//    private var dataFromServer = MutableLiveData<MutableList<Double>>()


//    val list = mutableListOf<RobotTechListInfo>()
//
//    var point22 :PointData = PointData()//实例化数据对象
//    //创建数组,包含所有值,方便调用
//    var pointValueArrayFormJson = arrayOf(point22.Cartesian.Z)

    //获取当前点信息
    fun getCurrentPointValue(currentName:String){
        //getRobotPointData(currentNameFromPointList,"value")
        getRobotPointData(currentName,"value")
        if((robotPointValueStr.value?.status ?: -1) >= 0){
            //firstGetByPointNameIndex
            if(firstGetByPointValueIndex){
                firstGetByPointValue = robotPointValueStr.value!!.value
                firstGetByPointValueIndex = false
            }
            //
            val pointValueByJsonFromServer = robotPointValueStr.value!!.value.replace("""\""","") //replace 要写在字符串后面
            val point = Json{ignoreUnknownKeys = true}.decodeFromString<RobotPointData>(pointValueByJsonFromServer.trimMargin())
//            println("测试17:1515 JOsn数据能否提取")
//            println(point.Cartesian.Z)
            //var pointValueArrayFormJson= mutableListOf<Double>()
//            val pointValueArrayFormJson = mutableListOf(point.Extj1,point.Extj2,point.Cylindrical.R,point.Cylindrical.T,point.Cylindrical.Z,point.Joint.Joint1,point.Joint.Joint2,
//            point.Joint.Joint3,point.Joint.Joint4,point.Joint.Joint5,point.Joint.Joint6,point.Cartesian.X,point.Cartesian.Y,
//            point.Cartesian.Z,point.Cartesian.Rx,point.Cartesian.Ry,point.Cartesian.Rz)
            val pointValueArrayFormJson = mutableListOf(point.PointData.Extj1,point.PointData.Extj2,point.PointData.Cylindrical.R,point.PointData.Cylindrical.T,point.PointData.Cylindrical.Z,point.PointData.Joint.Joint1,point.PointData.Joint.Joint2,
                point.PointData.Joint.Joint3,point.PointData.Joint.Joint4,point.PointData.Joint.Joint5,point.PointData.Joint.Joint6,point.PointData.Cartesian.X,point.PointData.Cartesian.Y,
                point.PointData.Cartesian.Z,point.PointData.Cartesian.Rx,point.PointData.Cartesian.Ry,point.PointData.Cartesian.Rz)
            //println("1613${pointValueArrayFormJson[16]}")
//            posListOfExtJoint.add(0,pointValueArrayFormJson[0])
//            posListOfExtJoint.add(1,pointValueArrayFormJson[1])
            //
            for (i in 0 until 2) {
                posListOfExtJoint.add(i,pointValueArrayFormJson[i])
            }
            for (i in 0 until 6) {
                posListOfCartes.add(i,pointValueArrayFormJson[i+11] )
            }
            for (i in 0 until 6) {
                posListOfJoints.add(i,pointValueArrayFormJson[i+5])
            }
            for (i in 0 until 3) {
                posListOfCylind.add(i, pointValueArrayFormJson[i+2])
            }
            pointConfig = point.PointData.Config.toDouble()
            pointIntroduction = point.Introduction
            pointTeached = point.Teached
//            dataFromServer.value = pointValueArrayFormJson
        }
        else{
            for (i in 0 until 2) {
                posListOfExtJoint.add(i,404.000)
            }
            for (i in 0 until 6) {
                posListOfCartes.add(i,404.000 )
            }
            for (i in 0 until 6) {
                posListOfJoints.add(i,404.000)
            }
            for (i in 0 until 3) {
                posListOfCylind.add(i, 404.000)
            }
        }
    }
    //通讯
    fun getRobotPointData(name: String,value: String) {
        runBlocking {
            val sendMessage = Robot.StringMSG.newBuilder()
                .setName(name)
                .setValue(value)
                .build()
            val data = GrpcConnectionManager.getStub()
                .getRobotPointData(sendMessage)
            robotPointValueStr.postValue(data)//从服务端获取的内容
        }
        println("打印获取的value")
        println(robotPointValueStr.value)
    }
    //Json解析与数组返回
//    fun jsonHandle(jsonValueFromServer:String): Array<Double>{
//        val pointValueByJsonFromServer = jsonValueFromServer.replace("""\""","") //replace 要写在字符串后面
//        //println(pointValueByJsonFromServer)
//        //解析
//        val point = Json{ignoreUnknownKeys = true}.decodeFromString<PointData>(pointValueByJsonFromServer.trimMargin())
//        println("测试17:1456 JOsn数据能否提取")
//        println(point.Cartesian.Z)
//        val pointValueArrayFormJson1 = arrayOf(point.Cartesian.Z)
//        println("数组是$pointValueArrayFormJson1")
//        return pointValueArrayFormJson1
//    }

//    val jsonValue =
//    """{\"Cartesian\":{\"Rx\":0.0,\"Ry\":0.0,\"Rz\":0.0,\"X\":0.0,\"Y\":0.0,\"Z\":0.0},\"Config\":-858993460,\"Cylindrical\":{\"J234\":0.0,\"R\":0.0,\"T\":0.0,\"Z\":0.0},\"Extj1\":0.0,\"Extj2\":0.0,\"Joint\":{\"Joint1\":0.0,\"Joint2\":0.0,\"Joint3\":0.0,\"Joint4\":0.0,\"Joint5\":0.0,\"Joint6\":0.0}}"""
//    //传入的json为列表类型
//    val json = "{\"code\":\"00001\",\"message\":\"test\",\"warnMessage\":\"test\"}"
//    fun testJson() {
//    val objPOint = Json.parseToJsonElement("""{"a":42}""")
//    println("测试1437 JOsn数据能否提取")
//    println(objPOint.jsonObject.values)

//    val point14 = Json.parseToJsonElement("""{\"Cartesian\":{\"Rx\":0.0,\"Ry\":0.0,\"Rz\":0.0,\"X\":0.0,\"Y\":0.0,\"Z\":0.0},\"Config\":-858993460,\"Cylindrical\":{\"J234\":0.0,\"R\":0.0,\"T\":0.0,\"Z\":0.0},\"Extj1\":0.0,\"Extj2\":0.0,\"Joint\":{\"Joint1\":0.0,\"Joint2\":0.0,\"Joint3\":0.0,\"Joint4\":0.0,\"Joint5\":0.0,\"Joint6\":0.0}}""")
//    println("测试1444 JOsn数据能否提取")
//    println(point14.jsonObject.values)


//    //val point15 = Json.encodeToJsonElement(PointData.serializer(),"""{\"Cartesian\":{\"Rx\":0.0,\"Ry\":0.0,\"Rz\":0.0,\"X\":0.0,\"Y\":0.0,\"Z\":0.0},\"Config\":-858993460,\"Cylindrical\":{\"J234\":0.0,\"R\":0.0,\"T\":0.0,\"Z\":0.0},\"Extj1\":0.0,\"Extj2\":0.0,\"Joint\":{\"Joint1\":0.0,\"Joint2\":0.0,\"Joint3\":0.0,\"Joint4\":0.0,\"Joint5\":0.0,\"Joint6\":0.0}}""")
    /**************
     * 先建立数据结构,再获得值
     * ****************/
   // {\"Cartesian\":{\"Rx\":0.0,\"Ry\":0.0,\"Rz\":0.0,\"X\":10.0,\"Y\":200.0,\"Z\":300.0},\"Cylindrical\":{\"R\":0.0,\"T\":0.0,\"Z\":0.0},\"Extj1\":0.0,\"Extj2\":0.0,\"Joint\":{\"Joint1\":0.0,\"Joint2\":0.0,\"Joint3\":0.0,\"Joint4\":0.0,\"Joint5\":0.0,\"Joint6\":0.0}}
    //    var pointValueByJsonFromServer = """{\"Cartesian\":{\"Rx\":0.0,\"Ry\":0.0,\"Rz\":0.0,\"X\":0.0,\"Y\":0.0,\"Z\":0.0},\"Config\":-858993460,\"Cylindrical\":{\"J2\":0.0,\"R\":0.0,\"T\":0.0,\"Z\":0.0},\"Extj1\":0.0,\"Extj2\":0.0,\"Joint\":{\"Joint1\":0.0,\"Joint2\":0.0,\"Joint3\":0.0,\"Joint4\":0.0,\"Joint5\":0.0,\"Joint6\":0.0}}"""
//    val pointValueByJsonFromServer ="""{\"Cartesian\":{\"Rx\":0.0,\"Ry\":0.0,\"Rz\":0.0,\"X\":10.0,\"Y\":200.0,\"Z\":300.0},
//        |\"Cylindrical\":{\"R\":0.0,\"T\":0.0,\"Z\":0.0},
//        |\"Extj1\":0.0,\"Extj2\":0.0,
//        |\"Joint\":{\"Joint1\":123.0,\"Joint2\":456.0,\"Joint3\":0.0,
//        |\"Joint4\":0.0,\"Joint5\":0.0,\"Joint6\":0.0}}""".replace("""\""","")
//    val pointValueByJsonFromServer = "{\"Cartesian\":{\"Rx\":0.0,\"Ry\":0.0,\"Rz\":0.0,\"X\":10.0,\"Y\":200.0,\"Z\":300.0},\"Cylindrical\":{\"R\":0.0,\"T\":0.0,\"Z\":0.0},\"Extj1\":0.0,\"Extj2\":0.0,\"Joint\":{\"Joint1\":0.0,\"Joint2\":0.0,\"Joint3\":0.0,\"Joint4\":0.0,\"Joint5\":5.0,\"Joint6\":6.0}}".replace("""\""","")
//    //上边的replace 要写在字符串后面
//    //pointValueByJsonFromServer.replace("""\""","")
//    //println(pointValueByJsonFromServer)
//    val point16 = Json{ignoreUnknownKeys = true}.decodeFromString<PointData>(pointValueByJsonFromServer.trimMargin())
//    println("测试1456 JOsn数据能否提取")
//    println(point16.Joint.Joint6)
/********************************/
//使用object得到json对象
//    val jsonString1 ="{\"Cartesian\":{\"Rx\":0.0,\"Ry\":0.0,\"Rz\":0.0,\"X\":10.0,\"Y\":200.0,\"Z\":300.0},\"Cylindrical\":{\"R\":0.0,\"T\":0.0,\"Z\":0.0},\"Extj1\":588.0,\"Extj2\":0.0,\"Joint\":{\"Joint1\":123.0,\"Joint2\":456.0,\"Joint3\":0.0,\"Joint4\":0.0,\"Joint5\":0.0,\"Joint6\":0.0}}"
//    val jsonObject = JSONObject(jsonString1)
    val name1  = jsonObject.getInt("a")
    val name = jsonObject.getString("name")
    val age = jsonObject.getInt("age")

    println("Name: $name, Age: $age,name1:$name1")
//    val joint1 = jsonObject.getDouble("Extj1")
//    println("答应04171228      $joint1")
//    var print = jsonObject.getJSONObject("Cartesian").get("X")?:null
//    if(print == null){
//        print = null
//    }
//    println("print是$print")
/******************************************/
//    val point16 = Json.decodeFromString<MyModel>("""{"a": 42, "b": "42"}""")
//    println("测试1456 JOsn数据能否提取")
//    println(point16.a)//

//    val JsonString17 ="""{\"a\": 42, \"b\": "42"}""".replace("""\""","")
//    val point17 = Json.decodeFromString<MyModel>(JsonString17)
//    println("测试1456 JOsn数据能否提取")
//    println(point17.a)

//    val stringofgang = """ni\ga\ga\ag""".replace("""\""","")
//    println("测试1528 斜杠能不能去掉")
//    println(stringofgang)
//    传入的json为数组类型
//    val jsonArray = "[{\"zoneNumber\":\"00001\",\"roomNumber\":\"test\",\"bedNumber\":\"test\"}]"
//
//
//    val jsonString = """
//    {
//       "type":"Foo",
//       "data":[
//          {
//             "id":1,
//             "title":"Hello"
//          },
//          {
//             "id":2,
//             "title":"World"
//          }
//       ]
//    }
//"""
//    val foos = Response(jsonString)
//    println("JsonString")
//    println(foos)


}
//class Response(json: String) : JSONObject(json) {
//    val type: String? = this.optString("type")
//    val data = this.optJSONArray("data")
//        ?.let { 0.until(it.length()).map { i -> it.optJSONObject(i) } } // returns an array of JSONObject
//        ?.map { Foo(it.toString()) } // transforms each JSONObject of the array into Foo
//}

//class Foo(json: String) : JSONObject(json) {
//    val id = this.optInt("id")
//    val title: String? = this.optString("title")
//}
//@Serializable
//data class MyModel(val a: Int,  val b: String = "42")
/***************************************************************************数据结构先放在这里*******/
//@Serializable
//data class StCylindrical(
//    var R: Double  = 0.0,
//    var T: Double  = 0.0,
//    var Z: Double  = 0.0,
//    var J234: Double = 0.0,
//)
//@Serializable
//data class StJoint(
//    var Joint1:Double = 0.0,
//    var Joint2:Double = 0.0,
//    var Joint3:Double = 0.0,
//    var Joint4:Double = 0.0,
//    var Joint5:Double = 0.0,
//    var Joint6:Double = 0.0,
//)
//@Serializable
//data class StCartesian(
//    var X:Double = 0.0,
//    var Y:Double = 0.0,
//    var Z:Double = 0.0,
//    var Rx:Double = 0.0,
//    var Ry:Double = 0.0,
//    var Rz:Double = 0.0,
//)
//@Serializable
//data class PointData(
//    var Cylindrical: StCylindrical = StCylindrical(),
//    var Joint: StJoint = StJoint(),
//    var Cartesian:StCartesian = StCartesian(),
//    var Config: Int = 1,
//    var Extj1:Double = 0.0,
//    var Extj2:Double = 0.0,
//)
@Serializable
data class StCylindrical(
    var R: Double  = 0.0,
    var T: Double  = 0.0,
    var Z: Double  = 0.0,
    var J234: Double = 0.0,
)
@Serializable
data class StJoint(
    var Joint1:Double = 0.0,
    var Joint2:Double = 0.0,
    var Joint3:Double = 0.0,
    var Joint4:Double = 0.0,
    var Joint5:Double = 0.0,
    var Joint6:Double = 0.0,
)
@Serializable
data class StCartesian(
    var X:Double = 0.0,
    var Y:Double = 0.0,
    var Z:Double = 0.0,
    var Rx:Double = 0.0,
    var Ry:Double = 0.0,
    var Rz:Double = 0.0,
)
@Serializable
data class PointData(
    var Cylindrical: StCylindrical = StCylindrical(),
    var Joint: StJoint = StJoint(),
    var Cartesian:StCartesian = StCartesian(),
    var Config: Int = 1,
    var Extj1:Double = 0.0,
    var Extj2:Double = 0.0,
)
@Serializable
data class RobotPointData(
    var Introduction: String = "" ,
    var Name: String = "",
    var PointData: PointData = PointData(),
    var Teached: Boolean = false,
)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值